本文實例為大家分享了QT實現FTP上傳文件的具體代碼,供大家參考,具體內容如下
兩台電腦通過網線建立本地連接,保證網關在同一段;
伺服器端打開ftp;
控制面板→程序→啟用或關閉windows功能→windows功能→Internet信息服務
啟用「FTP服務」FTP擴展性」 IIS管理控制台」
開始屏幕的搜索中輸入「IIS」,然後點擊打開「IIS管理器」
打開「IIS管理器」後,在左欄的「網站」上點擊右鍵,打開「添加FTP站點」
然後按照提示填寫站點信息
點擊「下一步」,按照下圖提示,設置「綁定和SSL設置」,在「IP地址」處,可以用內網IP也可以用外網IP,訪客自然也就根據你的IP設定來決定;
點擊「下一步」,設置「身份驗證和授權信息」
然後在本機瀏覽器地址欄中輸入「ftp://填寫的IP」測試一下
客戶端網頁測試遠程訪問;
客戶端(另一台電腦)瀏覽器地址欄中輸入「ftp://填寫的IP」測試一下
客戶端cmd測試遠程訪問;
win+r打開運行窗口,輸入cmd
回車打開cmd命令窗口
cmd命令中輸入:ftp回車
回車切換至ftp命令窗口,輸入命令:open,回車提示:到
到即所要連接測試的ftp地址,我們輸入:IP 22
即:ip地址+空格+埠號,沒有+號
回車後彈出用戶一行,輸入ftp的用戶名後回車,輸入ftp用戶名對應的密碼
輸入密碼後回車,如果提示,user logged in就說么ftp創建無問題
客戶端程序測試遠程訪問。
新建程序,添加ftpclass.cpp、ftpclass.h,復制main.cpp內容到程序入口函數
注意:/項目-屬性-常規-字元集-使用多位元組字元集/
//main.cpp
#include "stdafx.h"
#include "ftpclass.h"
void main()
{
printf("------- 開始測試!------\n");
printf("01--創建連接 %d\n", FtpClass::createConnection());
printf("02--打開目標ftp %d\n", FtpClass::createTable());
/*可以讀取ini內參數
FtpClass::ftp_Ip = TEXT("Ini讀取");
FtpClass::ftp_Port = TEXT("Ini讀取");
FtpClass::ftp_User = TEXT("Ini讀取");
FtpClass::ftp_Password = TEXT("Ini讀取");
FtpClass::ftp_Fixed_Path = TEXT("Ini讀取");*/
printf("03--創建文件夾 %d\n", FtpClass::createFolder("自動生成目錄1","自動生成目錄2","自動生成目錄3"));
/*上傳目標路徑*/
printf("04--上傳文件 %d\n", FtpClass::insert( "D:/a.txt", "b.txt"));
/*本機文件需要上傳文件*/ /*上傳後文件名稱,可以和本地文件名稱不一樣,類型最好別換*/
printf("05--關閉通訊 %d\n", FtpClass::createClose());
printf("------ 結束測試!------\n");
return ;
}
//ftpclass.h
/*項目-屬性-常規-字元集-使用多位元組字元集*/
/*wininet.lib、shlwapi.lib可以直接添加到附加依賴項*/
/*BOOL_VERIFY、NULL_VERIFY 程序結束判斷*/
#pragma once
#pragma comment(lib,"wininet.lib")
#pragma comment(lib,"shlwapi.lib")
#define BOOL_VERIFY(emStatus_bool,switch_bool) \
if (emStatus_bool == true)\
{return true;}\
else{\
if (switch_bool == 3) printf(" FTP_03_err:創建文件夾失敗!%d\n"); \
if (switch_bool == 4) printf(" FTP_04_err:上傳文件失敗!\n"); \
if (switch_bool == 5) printf(" FTP_05_err:關閉窗口句柄失敗!\n"); \
return false;\
}
#define NULL_VERIFY(emStatus_null,switch_null) \
if (emStatus_null != NULL)\
{return true;}\
else{\
if (switch_null == 1) {printf(" FTP_01_err:打開通訊錯誤 Error:%d\n", GetLastError());}\
if (switch_null == 2) {printf(" FTP_02_err:建立連接錯誤 Error:%d\n", GetLastError());}\
return false;\
}
#include "stdafx.h"//沒用
#include <afxinet.h>//MFC相關
#include "wininet.h"//調用FTP相關類
#include "shlwapi.h"//調用文件操作相關類
class FtpClass
{
public:
/*ini讀取變數*/
static CString ftp_Ip;//目標ip
static CString ftp_Port;//目標埠
static CString ftp_User;//目標賬戶
static CString ftp_Password;//目標密碼
static CString ftp_Fixed_Path;//目標固定路徑
static CString ftp_Free_Path;//目標自己生成路徑
/*全局變數*/
static BOOL pRes;
static HINTERNET hInternet;
static HINTERNET hConnect;
/*全局函數*/
static bool createConnection(); //創建一個連接
static bool createTable();
static bool ThreadInternetConnect(PVOID )
//打開目標ftp
static bool createFolder(CString temp1, CString temp2, CString temp3); //上傳文件
static bool insert(CString temp, CString temp1); //出入數據
static bool createClose(); //斷開連接
};
//ftpclass.cpp
#include "stdafx.h"
#include "ftpclass.h"
CString FtpClass::ftp_Ip = TEXT("192.168.3.104");
CString FtpClass::ftp_Port = TEXT("21");
CString FtpClass::ftp_User = TEXT("Administrator");
CString FtpClass::ftp_Password = TEXT("xinxin");
CString FtpClass::ftp_Fixed_Path = TEXT("1級固定目錄/2級固定目錄/3級固定目錄");
CString FtpClass::ftp_Free_Path = TEXT("自動生成目錄");
BOOL FtpClass::pRes = false;
HINTERNET FtpClass::hInternet = NULL;
HINTERNET FtpClass::hConnect = NULL;
//創建一個連接
bool FtpClass::createConnection() {
/*ftp_Ip = TEXT("Ini讀取");
ftp_Port = TEXT("Ini讀取");
ftp_User = TEXT("Ini讀取");
ftp_Password = TEXT("Ini讀取");
ftp_Fixed_Path = TEXT("Ini讀取");*/
hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT,
NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE);
NULL_VERIFY(hInternet,1);
}
bool FtpClass::ThreadInternetConnect(PVOID param) {
// 打開http
hConnect = InternetConnect(hInternet, ftp_Ip, INTERNET_DEFAULT_FTP_PORT,//INTERNET_DEFAULT_FTP_PORT 第三個參數默認值21
ftp_User, ftp_Password, INTERNET_SERVICE_FTP,
INTERNET_FLAG_EXISTING_CONNECT || INTERNET_FLAG_PASSIVE, 0);
return 1;
}
//打開目標ftp
bool FtpClass::createTable()
{
/*hConnect = InternetConnect(hInternet, ftp_Ip, 25,//INTERNET_DEFAULT_FTP_PORT 第三個參數默認值21
ftp_User, ftp_Password, INTERNET_SERVICE_FTP,
INTERNET_FLAG_EXISTING_CONNECT || INTERNET_FLAG_PASSIVE, 0);
NULL_VERIFY(hConnect,2);*/
HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadInternetConnect, (LPVOID)NULL, 0, NULL);
//超時3秒,如果等待結果是超時
if (WaitForSingleObject(hThread, 3 * 1000) == WAIT_TIMEOUT) {
TerminateThread(hThread, 0);
CloseHandle(hThread);
NULL_VERIFY(hConnect, 2);
}
NULL_VERIFY(hConnect, 2);
}
//上傳文件
bool FtpClass::createFolder(CString temp1, CString temp2, CString temp3)
{
/*新建文件件每次只能創建一級,多個需要分多次創建*/
pRes = false;
ftp_Free_Path = "";
ftp_Free_Path = ftp_Fixed_Path + "/" + temp1;
FtpCreateDirectory(hConnect, ftp_Free_Path);
ftp_Free_Path = ftp_Free_Path + "/" + temp2;
FtpCreateDirectory(hConnect, ftp_Free_Path);
ftp_Free_Path = ftp_Free_Path + "/" + temp3;
pRes = FtpCreateDirectory(hConnect, ftp_Free_Path);
BOOL_VERIFY(pRes,3);
}
//出入數據
bool FtpClass::insert(CString temp, CString temp1)
{
pRes = false;
ftp_Free_Path = ftp_Free_Path + "/" +temp1;
pRes = FtpPutFile(hConnect, temp,/*本機文件*/
ftp_Free_Path, /*TEXT("一級目錄/二級目錄/三級目錄/a.txt"),*/
FTP_TRANSFER_TYPE_ASCII, 0);
BOOL_VERIFY(pRes,4);
}
//斷開連接
bool FtpClass::createClose()
{
pRes = false;
if (InternetCloseHandle(hConnect))
pRes = InternetCloseHandle(hInternet);
BOOL_VERIFY(pRes,5);
}
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
Ⅱ 各位前輩,qt的源碼怎麼獲取,在哪裡可以看到
去qt官網下載源代碼。
在本地將源碼編譯。
使用剛才編譯的qt庫來調試,在程序加加斷點,就可以跟蹤進qt的源代碼。
Ⅲ Qt QFtp或QNetworkAccessManager中有沒有哪個成員能獲取FTP遠程文件的大小
qt5之後就不在使用QFtp QHttp,因為QNetworkaccessmanager已經替代了大部分功能,不知道digia在想啥,又不完全替換所有功能,有2種方法供用戶選擇
1現在編譯ftp源碼
2.使用第三方libcurl庫!
Ⅳ Qt現在是不是不提供完整的源碼包下載了
不是。
「http://www.qtsoftware.com/downloads」
在「LGPL/FREE」「Qt: Framework Only」里選平台,如Windows。
「http://www.qtsoftware.com/downloads/windows-cpp」
在「Source code available on this link:」這行字下面有
「http://get.qtsoftware.com/qt/source/qt-win-opensource-src-4.5.2.zip」
Ⅳ 誰有最新版QT下載地址200分等你來拿哦
Qt 是一個跨平台的 C++ 圖形用戶界面庫,由挪威 TrollTech 公司出品,目前包括Qt, 基於 Framebuffer 的 Qt Embedded,快速開發工具 Qt Designer,國際化工具 Qt Linguist 等部分 Qt 支持所有 Unix 系統,當然也包括 linux,還支持 WinNT/Win2k,Win95/98 平台。
.QT安裝
1.安裝環境
主機:Red Hat Fedora Core 4
編譯器:gcc-4.0.0-8 make-3.80-7
軟體:qt-x11-opensource-src-4.1.2.tar.gz
2.安裝過程
1).配置
$./configure [--option]
(具體配置選項可以用./configure --help查看,依據自己需要
選擇option)
2).編譯&建立
make
3).make install
3.建立環境變數
$PATH=/usr/local/Trolltech/Qt-4.1.2/bin:$PATH
$export PATH
$QTDIR=/usr/local/Trolltech/Qt-4.1.2
$export QTDIR
(可以在/etc/profile文件中添加如下兩行
PATH=/usr/local/Trolltech/Qt-4.1.2/bin:$PATH
QTDIR=/usr/local/Trolltech/Qt-4.1.2
export QTDIR PATH
)
4.安裝psql, odbc, sqlite, mysql的驅動
在configure的時候,要加上如下配置項
$./configure -plugin-sql-mysql -plugin-sql-sqlite -plugin-sql-odbc \
>-plugin-sql-psql
修改一下文件src/plugins/sqldrivers/mysql/mysql.pro在最開始處,
加上下面兩行
INCLUDEPATH += /usr/include/mysql
LIBS += -L/usr/lib/mysql
(否則可能會提示找不到mysql函數)
保存後,退出來,然後運行
$./configure -plugin-sql-mysql -plugin-sql-sqlite -plugin-sql-odbc \
>-plugin-sql-psql -continue
$make
$make install
轉到src/plugins/sqldrivers/mysql/目錄下,運行
make
然後把plugins/sqldrivers/目錄下面的libqsqlmysql.so,
libqsqlmysql_debug.so拷貝到/usr/local/Trolltech/Qt
4.1.0/plugins/sqldrivers目錄下面,完成
下載地址:
ftp://ftp.trolltech.com/qt/source/qt-win-opensource-4.3.2-mingw.exe
Ⅵ 討論上Windows平台怎麼編譯Qt5
Qt5的編譯官方有一篇wiki:http://developer.qt.nokia.com/wiki/Building_Qt_5_from_Git
簡要的總結下我的體會,歡迎補充完善、批評指正。
1.First clone the top-level qt5 git repository:
git clone git://gitorious.org/qt/qt5.git qt5
這一行不用說了,自然是將Qt5的代碼克隆。不過,如果你只是初次克隆Qt5的代碼,會很驚訝:為何克隆後的代碼只有十幾MB?
原來,Qt5已經實現了Qt的模塊化,詳見:http://labs.qt.nokia.com/2011/05/12/qt-moles-maturity-level-the-list/
所以可以在克隆得到的Qt5源碼根目錄下看到:.gitmoles 文件,其內容部分摘錄如下:
[submole "qtbase"]
path = qtbase
url = git://gitorious.org/qt/qtbase.git
[submole "qtsvg"]
path = qtsvg
url = git://gitorious.org/qt/qtsvg.git
[submole "qtdeclarative"]
path = qtdeclarative
url = git://gitorious.org/qt/qtdeclarative.git
...
這時,有Git基礎的朋友一定會想到:
git submole init
git submole update
不過,請不要這樣做!
2. Following the README file we initialize the repository. This clones the various sub-moles of Qt5:
./init-repository
這是一個perl腳本。如果是在msys-git下,會發現Perl的版本不夠。
我們需要安裝一個Windows版本的Perl:http://www.activestate.com/activeperl/downloads
安裝好以後,Perl就添加到PATH環境變數中去了。
在MSVC的控制台下執行:
perl init-repository --help
注意,不是直接執行init-repository,要用perl來執行它。看看幫助:大致了解下有哪些功能。
3. 注意它的三個小提示:
Hint1: If you』re going to contribute to Qt 5, you』ll need to pass the —codereview-username <Jira/Gerrit username> option to set up a 「gerrit」 remote for all the sub-moles.
Hint2: If you』re having problems downloading the webkit repository (which is quite big), you can pass —no-webkit.
Hint3: If you』re behind a firewall, pass —http
4. 我的方法:
perl init-repository -f --codereview-username loaden
這樣就可以實現子模塊的批處理了。特別要注意的是:在處理這些子模塊時,其實是git clone了這些子模塊,以致於他們可以獨立使用。在qt5\qtbase目錄下可以找到.git目錄。
這與git submole update的結果是不一樣的!!
同時我使用了codereview的用戶名,是為了可以創建一個名為gerrit的遠程倉庫,可以將貢獻的代碼推送進去,類似:
git push gerrit HEAD:refs/for/master
5. 源碼下載是非常慢的,因為QtWebkit達到了1.7GB。源碼下載完成後,進入Qt5源碼目錄,配置環境變數:
set PATH=%CD%\qtbase\bin;%PATH%
之後echo看一下結果是否正確:
echo %PATH%
6. 建議直接在Qt5的源碼目錄下執行配置!
configure -confirm-license -opensource -release -shared -platform win32-msvc2010 -fast -no-stl -no-qt3support -nomake examples -nomake demos -nomake tests
7. 編譯全部模塊,直接執行nmake就可以了。如果只編譯一個模塊,可以這樣:
nmake mole-qtbase
雙擊打開Qt5目錄下的Makefile文件,可以看到有這些模塊:
SUBTARGETS = \
mole-qtbase \
mole-qtsvg \
mole-qtphonon \
mole-qtxmlpatterns \
mole-qtdeclarative \
mole-qttools \
mole-qttranslations \
mole-qtdoc \
mole-qlalr \
mole-qtqa \
mole-qtlocation \
mole-qtactiveqt \
mole-qtsensors \
mole-qtsystems \
mole-qtmultimedia \
mole-qtfeedback \
mole-qtquick3d \
mole-qtdocgallery \
mole-qtpim \
mole-qtconnectivity \
mole-qtwayland \
mole-qtjsondb \
sub-qtwebkit-pri \
mole-qtwebkit-examples-and-demos
Ⅶ qt-win-opensource-src-5.2.1這個在哪裡下載
http://mirrors.ustc.e.cn/qtproject/official_releases/qt/5.2/5.2.1/single/qt-everywhere-opensource-src-5.2.1.zip
mySql沒弄過,自己去GG吧
Ⅷ 求助,我在linux下安裝的Qt5為什麼用GDB調試器無法進入源碼
打開命令終端面板輸入:sudo apt-get install gdb 如圖所示: 即可安裝,如果還是不可以,那就使用下面這種方式安裝: 打開終端輸入: wget ftp://ftp.gnu.org/gnu/gdb/gdb-7.9.tar.gz 下載完畢後解壓 tar -zxvf /gdb-7.9.tar.gz 然後進行安裝即可
Ⅸ 請問大佬有qt5quick.dll V1.0軟體免費百度雲資源嗎
《qt5quick.dll V1.0》網路網盤免費下載
鏈接: https://pan..com/s/1q45GPOLAV55t4jqK9kGhew
軟體名稱:qt5quick.dllV1.0
語言:簡體中文
大小:705KB
類別:系統工具
介紹:qt5quick.dll是電腦中非常重要的一個注冊表文件。如果缺少的話就會提示「無法找到qt5quick.dll」或「計算機缺少qt5quick.dll」,那麼用戶可以下載這個dll文件輕松修復問題!
《Qt5編程入門》霍亞飛程梁電子書網盤下載免費在線閱讀
鏈接:
書名:Qt5編程入門
作者名:霍亞飛程梁
出版社:北京航空航天大學出版社
出版年份:2015-1-30
頁數:388
內容介紹:
全新,基於 Qt 5.3 編寫,全面涉及 Qt Quick;經典,植根於 Qt 網路博客教程,可無限更新;基礎,對每個知識點詳盡講解,並設計了示常式序;系統,與《Qt Creator 快速入門(第2版)》相輔相成;
作者介紹:
霍亞飛:嵌入式軟體工程師,熱愛編程,熱愛開源!在博客中發表了大量Qt、Linux教程和開源軟體,被眾多網友奉為經典!參與創建Qt愛好者社區,進行Qt及開源項目的推廣和普及!程梁:軟體研發工程師,關注IT技術的創新和改革,專注於Qt技術開發教程的編寫。建立博客,創作大量有創意、實踐性強的技術開發文章,與廣大網友分享、互動,在網路上廣受好評。致力於帶領廣大Qt愛好者步入Qt的精彩世界,與更多朋友分享成功的樂趣。