|
|
@@ -22,20 +22,16 @@ Widget::Widget(QWidget *parent)
|
|
|
{
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
- // m_curlFtp.setFtpIPAndPort("192.168.50.100", 21);
|
|
|
-
|
|
|
- // m_curlFtp.setSftpIPAndPort("10.147.18.180", 21);
|
|
|
- // m_curlFtp.setUsernameAndPassword("microsoft", "19980714Lq");
|
|
|
- // m_curlFtp.setUsernameAndPassword("haxiaoxun@outlook.com", "147258369ztl");
|
|
|
-
|
|
|
- m_curlFtp.setFtpIPAndPort("192.1.2.178", 32021);
|
|
|
- m_curlFtp.setUsernameAndPassword("lh", "DWw7V9u0");
|
|
|
+ // m_curlFtp.setFtpIPAndPort("192.1.2.118", 21);
|
|
|
+ // m_curlFtp.setUsernameAndPassword("ftpOne", "123qwe");
|
|
|
+ /* SFTP测试 */
|
|
|
+ m_curlFtp.setSftpIPAndPort("192.1.2.118");
|
|
|
+ m_curlFtp.setUsernameAndPassword("Apple", "qweiop");
|
|
|
|
|
|
// m_curlFtp.setUsernameAndPassword("lh", "DWw7V9u0");
|
|
|
|
|
|
// m_curlFtp.setSftpIPAndPort("192.1.2.49", 32222);
|
|
|
// m_curlFtp.setUsernameAndPassword("lhftp", "8tG!2fP*7bJ@5kQ");
|
|
|
- // m_curlFtp.setIgnoreSSLCert(true);
|
|
|
m_curlFtp.enableCurlDebug(true);
|
|
|
|
|
|
SPDLOG_INFO("***** Qt Library *****");
|
|
|
@@ -47,113 +43,23 @@ Widget::~Widget()
|
|
|
delete ui;
|
|
|
}
|
|
|
|
|
|
-/* 解析JSON示例 */
|
|
|
-void Widget::parseJSON()
|
|
|
-{
|
|
|
- SPDLOG_INFO("解析JSON");
|
|
|
-
|
|
|
- nJson json0;
|
|
|
- json0["name"] = "microsoft";
|
|
|
- json0["age"] = 18;
|
|
|
- json0["bool"] = true;
|
|
|
- json0["null"] = nullptr;
|
|
|
- json0["array"] = {1, 2, 3, 4, 5};
|
|
|
- json0["object"] = {{"key1", "value1"}, {"key2", "value2"}};
|
|
|
-
|
|
|
- /* 打印json值 */
|
|
|
- SPDLOG_INFO("json0: {}", json0.dump());
|
|
|
-
|
|
|
- std::string name = json0["name"];
|
|
|
- std::string name2 = json0["name"].get<std::string>();
|
|
|
- std::string name1 = json0.at("name").get<std::string>();
|
|
|
- std::string name5 = json0.at("name");
|
|
|
- std::string name4 = json0.value("name", "default");
|
|
|
-
|
|
|
- int age = json0["age"].get<int>();
|
|
|
- bool b = json0["bool"];
|
|
|
- nJson null = json0["null"];
|
|
|
- nJson array = json0["array"];
|
|
|
- nJson object = json0["object"];
|
|
|
- /* 如果json中的值是null,在赋值给string时可能会报错,可以使用“?”运算符解决 */
|
|
|
- std::string name3 = json0["name"].is_null() ? "" : json0["name"].get<std::string>();
|
|
|
|
|
|
- /* 从直接到JSON */
|
|
|
- nJson json1 = R"(
|
|
|
- {
|
|
|
- "name": "microsoft",
|
|
|
- "age": 18,
|
|
|
- "bool": true,
|
|
|
- "null": null,
|
|
|
- "array": [1, 2, 3, 4, 5],
|
|
|
- "object": {
|
|
|
- "key1": "value1",
|
|
|
- "key2": "value2"
|
|
|
- }
|
|
|
- }
|
|
|
- )"_json;
|
|
|
+void Widget::on_pBtn_connect_clicked()
|
|
|
+{
|
|
|
+ SPDLOG_INFO("点击了“连接按钮”");
|
|
|
|
|
|
- /* 或者 */
|
|
|
- std::string str = R"(
|
|
|
+ std::vector<CF_FileInfo> fileInfoList;
|
|
|
+ m_curlFtp.getList("/home/Apple/Desktop/SFTP", fileInfoList);
|
|
|
+ for(auto& it : fileInfoList)
|
|
|
{
|
|
|
- "name": "microsoft",
|
|
|
- "age": 18,
|
|
|
- "bool": true,
|
|
|
- "null": null,
|
|
|
- "array": [1, 2, 3, 4, 5],
|
|
|
- "object": {
|
|
|
- "key1": "value1",
|
|
|
- "key2": "value2"
|
|
|
- }
|
|
|
+ SPDLOG_INFO("name = {}, type = {}, size = {}", it.name, (int)it.type, it.size);
|
|
|
}
|
|
|
- )";
|
|
|
- nJson json2 = nJson::parse(str);
|
|
|
|
|
|
- /* 从JSON到字符串 */
|
|
|
- std::string str1 = json0.dump();
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-void Widget::on_pBtn_connect_clicked()
|
|
|
-{
|
|
|
- SPDLOG_INFO("点击了“连接按钮”");
|
|
|
- // std::vector<std::string> list;
|
|
|
- // m_curlFtp.getFileList("/lh/Recall", list);
|
|
|
-
|
|
|
- // for(const std::string& filename : list)
|
|
|
- // {
|
|
|
- // QString qfilename = QString::fromLocal8Bit(filename.c_str());
|
|
|
- // SPDLOG_INFO("{}", qfilename.toStdString());
|
|
|
- // }
|
|
|
/* 创建文件夹 */
|
|
|
- // bool ret = m_curlFtp.createDirectories("/SSD2/lh/Recall/FlowChart/Data");
|
|
|
- // if(ret)
|
|
|
- // {
|
|
|
- // SPDLOG_INFO("Data 文件夹创建成功");
|
|
|
- // } else
|
|
|
- // {
|
|
|
- // SPDLOG_INFO("Data 文件夹创建失败");
|
|
|
- // }
|
|
|
- // ret = m_curlFtp.createDirectories("/lh/Recall/FlowChart/Image");
|
|
|
- // if(ret)
|
|
|
- // {
|
|
|
- // SPDLOG_INFO("Image 文件夹创建成功");
|
|
|
- // } else
|
|
|
- // {
|
|
|
- // SPDLOG_INFO("Image 文件夹创建失败");
|
|
|
- // }
|
|
|
-
|
|
|
- // m_curlFtp.createDirectory("/音乐");
|
|
|
- // m_curlFtp.createDirectory("/lh/GZHS/mysql/Chn_1/{bf9ae7ab-c85e-488c-8e81-1019b3dddf7a}/{a0d41558-9978-44fc-bae1-5756609622f1}/EQM_FlowChart/Data");
|
|
|
-
|
|
|
- std::vector<std::string> driList;
|
|
|
- // m_curlFtp.getDirList("/音乐", driList);
|
|
|
- m_curlFtp.getDirList("/lh/GZHS/mysql/Chn_1/{bf9ae7ab-c85e-488c-8e81-1019b3dddf7a}/{a0d41558-9978-44fc-bae1-5756609622f1}/EQM_FlowChart/Data", driList);
|
|
|
- for(auto& it : driList)
|
|
|
+ if(!m_curlFtp.createDirectory("/home/Apple/Desktop/SFTP/Video"))
|
|
|
{
|
|
|
- SPDLOG_INFO("{}", it);
|
|
|
+ SPDLOG_WARN("文件夹创建失败");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -164,8 +70,8 @@ void Widget::on_pBtn_downloadFile_clicked()
|
|
|
std::vector<std::string> fileList;
|
|
|
// bool ret = m_curlFtp.downloadFile("/SSD2/Video/哪吒之魔童降世.mp4", QApplication::applicationDirPath().toStdString() + "/YPM.mp4");
|
|
|
// bool ret = m_curlFtp.downloadFile("/SSD1/Video/v1.mp4", QApplication::applicationDirPath().toStdString() + "/v1.mp4");
|
|
|
- std::string remotePath = "/lh/GZHS/mysql/Chn_1/{bf9ae7ab-c85e-488c-8e81-1019b3dddf7a}/{a0d41558-9978-44fc-bae1-5756609622f1}/EQM_FlowChart/Data/Date.json";
|
|
|
- bool ret = m_curlFtp.downloadFile(remotePath, QApplication::applicationDirPath().toStdString() + "/Date.json");
|
|
|
+ std::string remotePath = "/FTP/0-0.wav";
|
|
|
+ bool ret = m_curlFtp.downloadFile(remotePath, QApplication::applicationDirPath().toStdString() + "/知否知否.wav");
|
|
|
if(ret)
|
|
|
{
|
|
|
SPDLOG_INFO("下载成功");
|
|
|
@@ -193,7 +99,7 @@ void Widget::on_pBtn_downloadVideo_clicked()
|
|
|
// {
|
|
|
// SPDLOG_INFO("下载失败");
|
|
|
// }
|
|
|
- bool ret = m_curlFtp.createDirectories("SSD1/DOC/123/234");
|
|
|
+ bool ret = m_curlFtp.createDirectory("SSD1/DOC/123/234");
|
|
|
if(ret)
|
|
|
{
|
|
|
SPDLOG_INFO("文件夹创建成功");
|
|
|
@@ -266,9 +172,20 @@ void Widget::on_pBtn_upload_clicked()
|
|
|
if(ret)
|
|
|
{
|
|
|
SPDLOG_INFO("上传成功");
|
|
|
- }
|
|
|
- else
|
|
|
+ } else
|
|
|
{
|
|
|
SPDLOG_INFO("上传失败");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+void Widget::on_pBtn_deleteFile_clicked()
|
|
|
+{
|
|
|
+ m_curlFtp.deleteFile("/home/Apple/Desktop/SFTP/Video/0-0.wav");
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void Widget::on_pBtn_deleteDir_clicked()
|
|
|
+{
|
|
|
+ m_curlFtp.deleteDirectory("/home/Apple/Desktop/SFTP/Video");
|
|
|
+}
|