【问题标题】:QFtp not sending packets in wiresharkQFtp不在wireshark中发送数据包
【发布时间】:2018-03-08 16:10:27
【问题描述】:

我正在学习如何使用 QFtp。

我想连接到远程 ftp 服务器并列出其内容。

这是我到目前为止写的:

// libftp.cpp
#include "libftp.h"

libFTP::libFTP(QObject *parent) :
    QObject(parent)
{
}

void libFTP::open(QString host)
{
    connect(&ftp,SIGNAL(commandFinished(int,bool)),this,SLOT(status(int,bool)));
    connect(&ftp,SIGNAL(listInfo(QUrlInfo)),this,SLOT(dir(QUrlInfo)));
    ftp.setTransferMode(QFtp::Active);
    ftp.connectToHost(host);
    ftp.list();
    ftp.cd("USER");
}

void libFTP::disconnect()
{
    ftp.abort();
    ftp.deleteLater();
}

void libFTP::download(QString filename)
{
    ftp.get(filename);
}

void libFTP::upload(QString path,QString filename)
{
    QString fullpath=path+filename;
    try
    {
      QFile *f= new QFile(fullpath);
      if(f->exists())
      {
          qDebug()<<"File Trovato";
          ftp.mkdir("test");
          //ftp.put(f,filename);
          f->close();
          f->deleteLater();
      }
    }
    catch(std::exception x)
    {
        qDebug()<<"Errore " << x.what();
    }
}

void libFTP::status(int id,bool error)
{
    if(error)
    {
        qDebug()<<"Errore";
    }
    else
        qDebug()<<"Status ID " << QString(id);
}

void libFTP::dir(QUrlInfo directory)
{
    qDebug()<<directory.name();
}

// libftp.h
#ifndef LIBFTP_H
#define LIBFTP_H

#include <QObject>
#include <QtCore>
#include <QFtp>
#include <QUrlInfo>
class libFTP : public QObject
{
    Q_OBJECT
public:
    explicit libFTP(QObject *parent = 0);
    void open(QString host);
    void disconnect();
    void download(QString filename);
    void upload(QString path,QString filename);

   private:
       QFtp ftp;

signals:

public slots:
    void status(int id,bool error);
    void dir(QUrlInfo directory);
};

#endif // LIBFTP_H

我从 main 调用它:

#include <libftp.h>
int main()
{
    libFTP *ftp = new libFTP();
    ftp->open("10.20.xx.xxx");
    ftp->deleteLater();
}

我要连接的服务器接受匿名登录。 当我尝试调试此代码时,我注意到没有调用任何插槽,并且在我的 wireshark 捕获中看不到任何 FTP 数据包。在我看到的每个示例代码中,这就是 QFtp 的使用方式,我缺少什么?

【问题讨论】:

  • 确保您下次在问题中将“文件”分开,以便更容易理解。
  • 在这里,对不起
  • 我已经给你做了,下次记住就好了。

标签: c++ qt qftp


【解决方案1】:

发现了问题,对于 qt 新手来说这不是立即的,它没有显示任何信息。 我必须在 QApplication 中运行 QFtp。我认为这是事件循环所需要的

在 main() 中调用 QApplication 解决了它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-10
    • 2017-05-25
    • 2014-03-19
    • 1970-01-01
    相关资源
    最近更新 更多