效果如图
下载按钮点击槽函数
//下载FTP服务器上的文件
void ftpWindow::on_downloadAction()
{
QTreeWidgetItem * download_item = ui->fileInfo_tw->currentItem();
QString tmpFileName = path+"/"+download_item->text(0);
file = new QFile(tmpFileName);
if(file->open(QIODevice::ReadWrite))
{
ftp->get(download_item->text(0),file);
}
}
path 是下载到的本地路径,因为是 ReadWrite 模式,所以没有文件会新建文件,有同名会覆盖
这里的 download_item->text(0) 是文件名
然后是上传演示
//上传到FTP服务器,如果同名,将会覆盖
void ftpWindow::on_download_btn_clicked()
{
file = new QFile("D:/Work/ftp_upload.txt");
if(file->open(QIODevice::ReadOnly))
{
QByteArray data = file->readAll();
ftp->cd(uploadPath)