{
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() ;
}
bool frmMainWindow::upLoadFile(QString checkcode,QString filename)
{
ftp = new QFtp(this);
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();
QString taskcode;
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////////
QString ftpPath;
ftpPath="/pisdata/"+taskcode;
ftpPath+="/image/";
ftp->cd(ftpPath);
//QFile file(filename);
file=new QFile(filename);
if (!file->open(QIODevice::ReadOnly))
{
file->close();
delete file;
return false;
}
QFileInfo fi(filename);
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() ;
}
To copy to clipboard, switch view to plain text mode
Bookmarks