风561 2024-12-15 03:37 采纳率: 0%
浏览 86
已结题

有偿求qftp工具。能连接,下载文件,发送代码,windows环境,最好qt6 要qt creator写的

有偿求qftp工具。windows环境,最好qt6,要qt creator写的
qt6编写,能通过ip连接linux,比如ip 172.20.51.115 22端口 root用户 密码2.2ltt
传输文件,发送指令
比方说我的linux里面的/root/SvrAgent_ForDebian_5/config.ini,这个配置文件需要更新,需要读取和下装
发送指令
为什么要用qt6,因为我修改config.in的程序使用qt6写的。。

"cd SvrAgent_ForDebian_5",        // 切换到目标目录
        "./uninstall.sh",                // 卸载旧版本
        "./install.sh"                   // 安装新版本
  • 写回答

38条回答 默认 最新

  • 阿里嘎多学长 2024-12-15 03:37
    关注
    获得0.50元问题酬金

    阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程

    QFTP工具实现

    你需要实现一个QFTP工具,可以连接到FTP服务器,下载文件和发送代码。下面是一个使用Qt6和Qt Creator实现QFTP工具的示例:

    首先,创建一个Qt6项目,选择Qt Widgets Application模板,然后添加以下依赖项:

    • Qt Network
    • Qt Widgets

    接下来,创建一个QFTP工具类,继承自QDialog:

    class QFtpTool : public QDialog {
        Q_OBJECT
    
    public:
        QFtpTool(QWidget *parent = nullptr);
        ~QFtpTool();
    
    private slots:
        void connectToFtp();
        void downloadFile();
        void uploadFile();
    
    private:
        QFtp *ftp;
        QComboBox *hostComboBox;
        QLineEdit *usernameEdit;
        QLineEdit *passwordEdit;
        QComboBox *portComboBox;
        QListView *fileList;
        QPushButton *connectButton;
        QPushButton *downloadButton;
        QPushButton *uploadButton;
    };
    

    实现QFTP工具类的构造函数和析构函数:

    QFtpTool::QFtpTool(QWidget *parent) : QDialog(parent) {
        ftp = new QFtp(this);
        ftp->set PassiveMode(true);
    
        hostComboBox = new QComboBox(this);
        usernameEdit = new QLineEdit(this);
        passwordEdit = new QLineEdit(this);
        portComboBox = new QComboBox(this);
        fileList = new QListView(this);
        connectButton = new QPushButton(tr("Connect"), this);
        downloadButton = new QPushButton(tr("Download"), this);
        uploadButton = new QPushButton(tr("Upload"), this);
    
        connect(connectButton, &QPushButton::clicked, this, &QFtpTool::connectToFtp);
        connect(downloadButton, &QPushButton::clicked, this, &QFtpTool::downloadFile);
        connect(uploadButton, &QPushButton::clicked, this, &QFtpTool::uploadFile);
    
        QVBoxLayout *layout = new QVBoxLayout(this);
        layout->addWidget(new QLabel(tr("Host:")));
        layout->addWidget(hostComboBox);
        layout->addWidget(new QLabel(tr("Username:")));
        layout->addWidget(usernameEdit);
        layout->addWidget(new QLabel(tr("Password:")));
        layout->addWidget(passwordEdit);
        layout->addWidget(new QLabel(tr("Port:")));
        layout->addWidget(portComboBox);
        layout->addWidget(fileList);
        layout->addWidget(connectButton);
        layout->addWidget(downloadButton);
        layout->addWidget(uploadButton);
    
        setLayout(layout);
    }
    
    QFtpTool::~QFtpTool() {
        delete ftp;
        delete hostComboBox;
        delete usernameEdit;
        delete passwordEdit;
        delete portComboBox;
        delete fileList;
        delete connectButton;
        delete downloadButton;
        delete uploadButton;
    }
    

    实现QFTP工具类的槽函数:

    void QFtpTool::connectToFtp() {
        QString host = hostComboBox->currentText();
        QString username = usernameEdit->text();
        QString password = passwordEdit->text();
        int port = portComboBox->currentIndex();
    
        ftp->connectToHost(host, port);
        ftp->login(username, password);
    }
    
    void QFtpTool::downloadFile() {
        QString file = fileList->currentIndex().toString();
        ftp->get(file, file);
    }
    
    void QFtpTool::uploadFile() {
        QString file = fileList->currentIndex().toString();
        ftp->put(file, file);
    }
    

    最后,使用Qt Creator编译和运行QFTP工具。

    这个示例只是一个基本的QFTP工具,实际实现中可能需要添加更多的功能和错误处理。

    评论

报告相同问题?

问题事件

  • 系统已结题 12月23日
  • 修改了问题 12月16日
  • 修改了问题 12月15日
  • 创建了问题 12月15日