PDA

View Full Version : Copy folder recursively from Remote Server to Host machine using Qftp protocol



iravi89
19th September 2016, 07:59
Hi,
I just want to copy directory recursively instead of files from server machine to host machine ,I am using Qftp protocol for that but i am only able to copy files individually which is not solving my purpose as there are lots of log file that i have to copy.
Here are the codes that i am using for copying files.



///************test ***
// QFileInfoList

QString fileName = fileList->currentItem()->text(0);

qDebug()<<"File name is :"<<fileName;

if (QFile::exists(fileName)) {
QMessageBox::information(this, tr("FTP"),
tr("There already exists a file called %1 in "
"the current directory.")
.arg(fileName));
return;
}

file = new QFile(fileName);
if (!file->open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("FTP"),
tr("Unable to save the file %1: %2.")
.arg(fileName).arg(file->errorString()));
delete file;
return;
}

ftp->get(fileList->currentItem()->text(0), file);


please help as i am stuck .:(

anda_skoa
19th September 2016, 09:32
There doesn't seem to be any recursion in your code, not even any hint of listing a directory on the server and processing its files.

Cheers,
_

iravi89
19th September 2016, 09:49
No its not,i my code i am just able to copy selected file only ,but there suppose to be lots of file there so its pain to select and copy each file individually. so i just want to copy whole directory.
I hope my point is clear to you.
Thanks for your time and consideration.
And here is my get function code
int QFtp::get(const QString &file, QIODevice *dev, TransferType type)
{
QStringList cmds;
if (type == Binary)
cmds << QLatin1String("TYPE I\r\n");
else
cmds << QLatin1String("TYPE A\r\n");
cmds << QLatin1String("SIZE ") + file + QLatin1String("\r\n");
cmds << QLatin1String(d->transferMode == Passive ? "PASV\r\n" : "PORT\r\n");
cmds << QLatin1String("RETR ") + file + QLatin1String("\r\n");
return d->addCommand(new QFtpCommand(Get, cmds, dev));
}

void FtpWindow::downloadFile()
{

progressDialog->setVisible(true);
//progressDialog = new QProgressDialog(this);

///************test ***
// QFileInfoList

QString fileName = fileList->currentItem()->text(0);

qDebug()<<"File name is :"<<fileName;

if (QFile::exists(fileName)) {
QMessageBox::information(this, tr("FTP"),
tr("There already exists a file called %1 in "
"the current directory.")
.arg(fileName));
return;
}

file = new QFile(fileName);
if (!file->open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("FTP"),
tr("Unable to save the file %1: %2.")
.arg(fileName).arg(file->errorString()));
delete file;
return;
}

ftp->get(fileList->currentItem()->text(0), file);


progressDialog->setLabelText(tr("Downloading %1...").arg(fileName));
downloadButton->setEnabled(false);
progressDialog->exec();
}