{"id":1869,"date":"2021-04-08T17:52:20","date_gmt":"2021-04-08T09:52:20","guid":{"rendered":"http:\/\/www.youthtribe.com\/?p=1869"},"modified":"2022-06-30T17:20:52","modified_gmt":"2022-06-30T09:20:52","slug":"qt%e4%b9%8bftp%e4%b8%8a%e4%bc%a0-%e4%b8%8b%e8%bd%bd%e6%96%87%e4%bb%b6%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"http:\/\/www.youthtribe.com\/archives\/1869","title":{"rendered":"Qt\u4e4bFTP\u4e0a\u4f20\/\u4e0b\u8f7d\u6587\u4ef6\u64cd\u4f5c"},"content":{"rendered":"\n

\u4e0a\u4f20\u6587\u4ef6<\/p>\n\n\n\n

QNetworkAccessManager manager;\nQUrl url;\n\/* \u8bbe\u7f6e\u901a\u8baf\u534f\u8bae *\/<\/em>\nurl.setScheme(\"ftp\");    \n\/* \u8bbe\u7f6e\u7528\u6237\u540d *\/<\/em>  \nurl.setUserName(\"root\");  \n\/* \u8bbe\u7f6e\u5bc6\u7801 *\/<\/em> \nurl.setPassword(\"123456\"); \n\/* \u8bbe\u7f6e\u4e3b\u673a\uff0c\u4e5f\u53ef\u4ee5\u662f\u57df\u540d *\/<\/em>\nurl.setHost(\"127.0.0.1\");\n\/* \u8bbe\u7f6e\u7aef\u53e3\u53f7\uff0c\u4e00\u822c\u4e3a21 *\/<\/em>  \nurl.setPort(21);         \n\/* \u8bbe\u7f6e\u8def\u5f84 *\/<\/em> \nurl.setPath(\"\/tmp\/hello.png\"); \n\n\/* \u88c5\u8f7d\u672c\u5730\u6587\u4ef6 *\/<\/em>\nQFile file(\"\/Desktop\/hello.png\"); \nfile.open(QIODevice::ReadOnly);\n\/* \u8bfb\u53d6\u672c\u5730\u6587\u4ef6\u6570\u636e *\/<\/em>\nQByteArray data = file.readAll(); \nfile.close();\n\nQNetworkRequest request(url);\n\/* \u4e0a\u4f20\u6570\u636e\uff0c\u4e0a\u4f20\u6210\u529f\u540e\u4f1a\u5728\u8fdc\u7aef\u521b\u5efa\/tmp\/hello.png\u6587\u4ef6 *\/<\/em>\nQNetworkReply* reply = manager.put(request, data); \n\nQEventLoop eventLoop; \nQObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));\n\/* \u8fdb\u5165\u7b49\u5f85\uff0c\u4f46\u4e8b\u4ef6\u5faa\u73af\u4f9d\u7136\u8fdb\u884c *\/<\/em>\neventLoop.exec(); \n\nif (reply->error() != QNetworkReply::NoError) {\n    qDebug() << \"Error: \" << reply->errorString();\n}<\/pre>\n\n\n\n

\u4e0b\u8f7d\u6587\u4ef6<\/p>\n\n\n\n

QNetworkAccessManager manager;\nQUrl url;\n\/* \u8bbe\u7f6e\u901a\u8baf\u534f\u8bae *\/<\/em>\nurl.setScheme(\"ftp\");      \n\/* \u8bbe\u7f6e\u7528\u6237\u540d *\/<\/em>\nurl.setUserName(\"root\");   \n\/* \u8bbe\u7f6e\u5bc6\u7801 *\/<\/em>\nurl.setPassword(\"123456\"); \n\/* \u8bbe\u7f6e\u4e3b\u673a\uff0c\u4e5f\u53ef\u4ee5\u662f\u57df\u540d *\/<\/em>\nurl.setHost(\"127.0.0.1\");  \n\/* \u8bbe\u7f6e\u7aef\u53e3\u53f7\uff0c\u4e00\u822c\u4e3a21 *\/<\/em>\nurl.setPort(21);           \n\/* \u8bbe\u7f6e\u8def\u5f84 *\/<\/em>\nurl.setPath(\"\/tmp\/test.txt\"); \n\nQNetworkRequest request(url);\n\/* \u6267\u884cGet\u8bf7\u6c42 *\/<\/em>\nQNetworkReply* reply = manager.get(request); \n\nQEventLoop eventLoop;\nQObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));\n\/* \u8fdb\u5165\u7b49\u5f85\uff0c\u4f46\u4e8b\u4ef6\u5faa\u73af\u4f9d\u7136\u8fdb\u884c *\/<\/em>\neventLoop.exec(); \n\nif (reply->error() == QNetworkReply::NoError) {\n    \/* \u521b\u5efa\u672c\u5730\u6587\u4ef6 *\/<\/em>\n    QFile file(\"test.txt\"); \n    file.open(QIODevice::WriteOnly);\n    \/* \u5199\u5165\u6587\u4ef6 *\/<\/em>\n    file.write(reply->readAll()); \n    file.close();\n}\nelse {\n    qDebug() << \"Error: \" << reply->errorString();\n}<\/pre>\n\n\n\n

\u603b\u7ed3<\/h3>\n\n\n\n
  • \u4e0a\u4f20\u6587\u4ef6\uff1a\u914d\u7f6eurl->\u52a0\u8f7d\u6570\u636e->put\u64cd\u4f5c<\/li>
  • \u4e0b\u8f7d\u6587\u4ef6\uff1a\u914d\u7f6eurl->get\u64cd\u4f5c->\u83b7\u53d6\u6570\u636e\u4fdd\u5b58\u5230\u6587\u4ef6<\/li>
  • \u5982\u670d\u52a1\u7aef\u6ca1\u6709\u8eab\u4efd\u9a8c\u8bc1\uff0c\u5ba2\u6237\u7aef\u53ef\u4ee5\u7701\u7565\u7528\u6237\u540d\u548c\u5bc6\u7801\u64cd\u4f5c\u3002<\/li><\/ul>\n\n\n\n

    https:\/\/zhuanlan.zhihu.com\/p\/92496797<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

    \u4e0a\u4f20\u6587\u4ef6 QNetworkAccessManager manager; QUrl url; \/* \u8bbe\u7f6e\u901a\u8baf\u534f\u8bae *\/ url.setScheme(“ftp”); \/* \u8bbe\u7f6e\u7528\u6237\u540d *\/ url.setUserName(“root”); \/* \u8bbe\u7f6e\u5bc6\u7801 *\/ url.setPassword(“123456”); \/* \u8bbe\u7f6e\u4e3b\u673a\uff0c\u4e5f\u53ef\u4ee5\u662f\u57df\u540d *\/ url.setHost(“127.0.0.1”); \/* \u8bbe\u7f6e\u7aef\u53e3\u53f7\uff0c\u4e00\u822c\u4e3a21 *\/ url.setPort(21); \/* \u8bbe\u7f6e\u8def\u5f84 *\/ url.setPath(“\/tmp\/hello.png”); \/* \u88c5\u8f7d\u672c\u5730\u6587\u4ef6 *\/ QFile file<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,296],"tags":[250,295],"_links":{"self":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1869"}],"collection":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/comments?post=1869"}],"version-history":[{"count":4,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1869\/revisions"}],"predecessor-version":[{"id":2001,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1869\/revisions\/2001"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=1869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=1869"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=1869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}