QFtp下载位置问题

时间:2011-01-03 10:24:04

标签: qt ftp qftp

我刚用Qt写了一个小ftp客户端。问题是当我下载时,ftp->get()命令将文件下载到默认位置。我想定义下载文件的路径。

这是我的DownloadFile方法:

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);

1 个答案:

答案 0 :(得分:1)

只需使用您想要的路径创建file对象,QFtp将保存在那里。喜欢的东西;

file = new QFile(QString("/path/to/download/%1").arg(fileName));