how to use qftp to upload file in just one procedure?
I just want to use qftp to upload a file .at first , i have to determine whether the dir exists or not. But how to implement the code to judge and at the same time upload file in one function?
just like that :
Qstringlist dirlist;
ftp.list(dirlist) ;
if (!dirlist.contain(onedir))
{
ftp.mkdir(onedir);
}
ftp.put(myFile) ;
Re: how to use qftp to upload file in just one procedure?
Not sure what you mean. What is wrong with the code you posted?
Re: how to use qftp to upload file in just one procedure?
before upload a file ,i want to determine if the parent dir existed . but how to do it? i know the flowing code will not work.
Code:
{
connect(ftp, SIGNAL(commandFinished(int, bool)),
this, SLOT(ftpCommandFinished(int, bool)) );
connect(ftp,
SIGNAL(listInfo
(const QUrlInfo &)),
this,
SLOT(ftpListInfo
(const QUrlInfo &)));
connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64) ),
this, SLOT(updateDataTransferProgress(qint64, qint64)));
ftp->connectToHost("192.168.1.3");
ftp->login("ftpuser","ftpuser");
fileList.clear();
ftp->cd("/pisdata/"); //init dir
ftp->list();
taskcode=checkcode.left(8);
//first to determine if parent dir exits.
if (!fileList.contains(taskcode)){ [COLOR="Red"] //fileList will not contain anything [/COLOR]
ftp->mkdir(taskcode);
ftp->cd(taskcode);
ftp->mkdir("pdf");
ftp->mkdir("image");
ftp->mkdir("xml");
ftp->cd("image");
}
else{
ftp->cd(taskcode);
fileList.clear();
ftp->list();
if(!fileList.contains("image",Qt::CaseInsensitive)){
ftp->mkdir("image");
}
ftp->cd("image");
}
//////////////start upload file////////
ftpPath="/pisdata/"+taskcode;
ftpPath+="/image/";
ftp->cd(ftpPath);
//QFile file(filename);
file=new QFile(filename
);
{
file->close();
delete file;
return false;
}
ftp->put(file,fi.fileName());
progressDialog->setLabelText(tr("put %1...").arg(fi.fileName()));
progressDialog->exec();
return true;
}
void frmMainWindow
::ftpListInfo(const QUrlInfo &urlInfo
) {
fileList<<urlInfo.name() ;
}
Re: how to use qftp to upload file in just one procedure?
The problem is that you do not wait for the ftp commands to complete ( either success or fail ). You do everything at once.
You should wait for every ftp command to complete and then go to next step.
You should make use of the commandStarted and commandFinished signals and queue the command id's as soon as you execute them( for list, mkdir, etc ).
Currently when you search in the file list it will be empty, because the list() command has not completed yet.
Regards
Re: how to use qftp to upload file in just one procedure?
yes, i know the reason.But how should i do ? write the code in ftpCommandFinished ?