Hi Liviu,
I tried to upload files to ftp server but some file are uploaded correctly but other are empty
I I did not understand what is my problem :(
QFtp *ftp = new QFtp(this);
//connect(ftp,SIGNAL(commandFinished ( int, bool)),this,SLOT(fincommande()));
ftp->connectToHost("ftp.icwus.net");
connect(ftp, SIGNAL(stateChanged(int)), this, SLOT(showNewState(int)));
ftp->login("mylog","mypw");
connect(ftp, SIGNAL(stateChanged(int)), this, SLOT(showNewState(int)));
ftp->cd("acrgafsa");
connect( ftp, SIGNAL( commandFinished( int, bool )),this, SLOT( ftp_commandFinished( int, bool )) );
int i = 0;
QString filename;
QString files = QFileDialog::getOpenFileName(this, tr("Select File"),
"D://");
if (files.isEmpty())
{ qDebug() <<"file is empty";
return;}
while(files.indexOf("/", i) != (-1)) //find the file name not include the full url
i = files.indexOf("/",i) + 1;
while(i < files.size())
{
filename.append(files.at(i));
i++;
}
QFile *file = new QFile(filename);
Q_ASSERT(file != NULL);
if(!file->open(QIODevice::ReadWrite)) //finished create the file in the debug file
{
qDebug() << "opern err" << file->fileName();
return;
}
qDebug() << "start upload";
QFileInfo fi(files);
ftp->put(file,fi.fileName());
connect( ftp, SIGNAL( commandFinished( int, bool )),this, SLOT( ftp1_commandFinished( int, bool )) );
qDebug() << "fin upload";
ftp->close();
Well, I tried to fix some problems in your code, like putting connections only once, at initialization. See code below:
QFtp *ftp = new QFtp(this);
//connect(ftp,SIGNAL(commandFinished ( int, bool)),this,SLOT(fincommande()));
ftp->connectToHost("ftp.icwus.net");
connect(ftp, SIGNAL(stateChanged(int)), this, SLOT(showNewState(int)));
//connect(ftp, SIGNAL(stateChanged(int)), this, SLOT(showNewState(int))); - duplicate
connect( ftp, SIGNAL( commandFinished( int, bool )),this, SLOT( ftp_commandFinished( int, bool )) );
connect( ftp, SIGNAL( commandFinished( int, bool )),this, SLOT( ftp1_commandFinished( int, bool )) );
ftp->login("mylog","mypw");
ftp->cd("acrgafsa");
int i = 0;
QString filename;
QString files = QFileDialog::getOpenFileName(this, tr("Select File"),
"D://");
if (files.isEmpty())
{ qDebug() <<"file is empty";
return;}
while(files.indexOf("/", i) != (-1)) //find the file name not include the full url
i = files.indexOf("/",i) + 1;
while(i < files.size())
{
filename.append(files.at(i));
i++;
}
QFile *file = new QFile(filename);
Q_ASSERT(file != NULL);
if(!file->open(QIODevice::ReadWrite)) //finished create the file in the debug file
{
qDebug() << "opern err" << file->fileName();
return;
}
qDebug() << "start upload";
QFileInfo fi(files);
ftp->put(file,fi.fileName());
qDebug() << "fin upload";
ftp->close();
I will try to help as possible, but I am not sure I can go through all your code. I am not sure I know what the problem is.
PS: I modified your message above, code should be between [ code ] ... [ / code ] tags, not [ quote ] ... [ / quote ]