0

I just wrote tiny ftp client using Qt. The problem is when I download, the ftp->get() command downloads the file to the default location. I'd like to define a path where the downloaded file will go.

This is my DownloadFile method:

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

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(fileListTreeWidget->currentItem()->text(0), file);
Daniel Hedberg
  • 5,677
  • 4
  • 36
  • 61
kaycee
  • 1,199
  • 4
  • 24
  • 42

1 Answers1

1

Just create the file object with the path you want and QFtp will save there. Something like;

file = new QFile(QString("/path/to/download/%1").arg(fileName));
ismail
  • 46,010
  • 9
  • 86
  • 95