亚洲ww无码ww专区1234_亚洲AV综合色区无码三区30p_丰满二级精品一区_美女黄频视频大全免费的正片_久久综合九色综合网站

如何用ftp傳輸文件_ftp上傳文件 當(dāng)前熱訊

2023-06-22 15:08:02    來源:互聯(lián)網(wǎng)

hello大家好,我是城鄉(xiāng)經(jīng)濟(jì)網(wǎng)小晟來為大家解答以上問題,如何用ftp傳輸文件(ftp上傳文件)很多人還不知道,現(xiàn)在讓我們一起來看看吧!

一、FTP服務(wù)器


(相關(guān)資料圖)

常用的FTP服務(wù)器有:Server-U,F(xiàn)ilezilla Server,IIS。

Server-U的特點(diǎn)是功能強(qiáng)大,但是需要收費(fèi)。

FileZilla Server是一種小巧、快速、可信賴的支持FTP以及SFTP的服務(wù)器端。它是開源的,并且具有很豐富的操作接口。

IIS是微軟自帶的FTP服務(wù)器,但是配置和操作非常的復(fù)雜。

Server-U

Filezilla Server

二、FTP客戶端

常見FTP客戶端工具:filezilla、LeapFTP、CuteFTP

filezilla

LeapFTP

CuteFTP

三、C FTP客戶端操作框架

C FTP客戶端框架:ftplibpp、ftplib、windows系統(tǒng)Wininet函數(shù)、libcurl、ftp.exe命令上傳與下載文件。

ftplibpp, 提供ftp客戶端功能的平立 C 庫,支持Linux、Mac、window系統(tǒng),支持 fxp, ssl/tl加密。https://github.com/mkulke/ftplibpp

ftplib, 提供ftp客戶端功能的平立 C庫,支持Linux (X86), Mac OS-X and OpenVMS (AXP)系統(tǒng)。http://nbpfaus.net/~pfau/ftplib/

windows系統(tǒng)Wininet函數(shù),https://docs.microsoft.com/zh-cn/windows/win32/wininet/ftp-sessions

注意:windows中ftp.exe命令上傳與下載文件方式比其他方式更加有效,其他方式不太穩(wěn)定。

1、ftplibpp

函數(shù)說明:https://www.helplib.com/GitHub/article_110777

vs2015工程如何使用ftplib?

1)添加ftplib.h ftplib.cpp文件到工程中。

2)預(yù)處理器定義中添加NOSSL NOLFS _CRT_SECURE_NO_WARNINGS

3)ftplib.h頭文件中增加

#include #ifndef _WIN32#include #include #else#include #endif

2、ftplib

函數(shù)說明:http://nbpfaus.net/~pfau/ftplib/ftplib.html

3、windows系統(tǒng)Wininet函數(shù)

步驟:

1) InternetOpen初始化一個(gè)Internet句柄。此句柄用于建立一個(gè)FTP session。

2)InternetConnect創(chuàng)建一個(gè)FTP session。INTERNET_DEFAULT_FTP_PORT for the nServerPort parameter and INTERNET_SERVICE_FTP for the dwService parameter.

3)執(zhí)行必要的操作。比如FtpPutFile、FtpGetFile、FtpDeleteFile、FtpRenameFile、FtpCreateDirectory、FtpRemoveDirectory、FtpGetCurrentDirectory、FtpSetCurrentDirectory等。

4)InternetCloseHandle關(guān)閉由InternetConnect創(chuàng)建的FTP session。

5)InternetCloseHandle關(guān)閉由InternetOpen創(chuàng)建的FTP session。

FtpCreateDirectory、FtpDeleteFile及之后的幾個(gè)函數(shù)都需要InternetConnect返回的句柄。

常見函數(shù)介紹:

HINTERNET InternetOpen(

LPCTSTR lpszAgent,// 指定調(diào)用 WinINet 函數(shù)的應(yīng)用程序或入口。該入口用作HTTP協(xié)議中用戶代理項(xiàng)。其實(shí)是自定義的名稱。如”MyFtp”、“mwj”等。

DWORD dwAccessType,//一般為INTERNET_OPEN_TYPE_PRECONFIG:返回注冊(cè)表中的代理或直接的配置。

LPCTSTR lpszProxyName,//一般為NULL。若參數(shù)dwAccessType不是INTERNET_OPEN_TYPE_PROXY,此參數(shù)應(yīng)被設(shè)為NULL。

LPCTSTR lpszProxyBypass,//一般為NULL。若參數(shù)dwAccessType不是INTERNET_OPEN_TYPE_PROXY,此參數(shù)應(yīng)被設(shè)為NULL。

DWORD dwFlags);// INTERNET_FLAG_ASYNC:僅能用于作用在該函數(shù)返回的句柄的子句柄上的異步請(qǐng)求。INTERNET_FLAG_OFFLINE 與 INTERNET_FLAG_FROM_CACHE 相同:不做網(wǎng)絡(luò)請(qǐng)求。所有的實(shí)體都由緩存返回。若請(qǐng)求條目不在緩存中,將返回一個(gè)錯(cuò)誤。對(duì)于遍歷FTP服務(wù)器上的文件夾時(shí),此參數(shù)必須為0。

HINTERNET WINAPI InternetConnect(

HINTERNET hInternet, //InternetOpen返回的句柄

LPCTSTR lpszServerName, //要連接的Internet server的名字或IP

INTERNET_PORT nServerPort, //對(duì)FTP用INTERNET_DEFAULT_FTP_PORT

LPCTSTR lpszUserName, //對(duì)FTP可用“anonymous”。設(shè)為NULL,對(duì)FTP將自動(dòng)設(shè)為anonymous

LPCTSTR lpszPassword, //若為NULL,對(duì)FTP則自動(dòng)使用anonymous的默認(rèn)密碼

DWORD dwService, //對(duì)FTP用INTERNET_SERVICE_FTP

DWORD dwFlags, //一般為0

DWORD dwContext);//一般為0

此函數(shù)不僅可連接FTP還可連接HTTP。返回NULL表明連接失敗。

FtpFindFirstFile和InternetFindNextFile遍歷ftp文件

WIN32_FIND_DATA fd;HINTERNET hFind = FtpFindFirstFile(hFtpSession, "/*.*", &fd, INTERNET_FLAG_RELOAD, 0);if(hFind != INVALID_HANDLE_VALUE){ BOOL bFind = TRUE; while(bFind) { bFind = InternetFindNextFile(hFind, &fd); OutputDebugString(fd.cFileName); OutputDebugString("\n"); }}InternetCloseHandle(hFind);實(shí)例:#include void main(){ BOOL dRes,pRes; HINTERNET hInternet; HINTERNET hConnect; hInternet = InternetOpen("Test Sample", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE); if ( NULL == hInternet ) { printf("InternetOpen Error:%d\n", GetLastError() ); } hConnect = InternetConnect(hInternet, "127.0.0.1"/*FTP服務(wù)器地址*/, INTERNET_DEFAULT_FTP_PORT/*FTP端口號(hào),此為默認(rèn)值---21*/, "admin"/*用戶名*/, "123456"/*密碼*/, INTERNET_SERVICE_FTP, INTERNET_FLAG_EXISTING_CONNECT || INTERNET_FLAG_PASSIVE,0 ); if ( NULL == hInternet ) { printf( "InternetConnect Error:%d\n", GetLastError() ); InternetCloseHandle(hInternet); }dRes = FtpGetFile(hConnect, "./download/test.txt", "D:\\test.txt", FALSE, FILE_ATTRIBUTE_ARCHIVE, FTP_TRANSFER_TYPE_UNKNOWN, 0); if ( dRes == 0 ) { printf( "FtpGetFile Error:\n", GetLastError() ); }else{ printf( "下載文件成功!\n" ); } pRes = FtpPutFile(hConnect,"D:\\test.txt","test.txt",FTP_TRANSFER_TYPE_ASCII,0); if(pRes==0) { printf("上傳文件失?。n"); }else{ printf("上傳文件成功!\n"); } InternetCloseHandle(hConnect); InternetCloseHandle(hInternet); if(dRes&&pRes) return true; else return false;

4、libcurl實(shí)現(xiàn)ftp客戶端(上傳、下載、進(jìn)度、斷點(diǎn)續(xù)傳)

https://blog.csdn.net/wu110112/article/details/72898630

https://blog.csdn.net/u012234115/article/details/83869486

5、ftp.exe命令上傳文件

bool FtpUploadFile(std::string strUuid,std::string strIp,int nPort,std::stringstrLoginUsername,std::string strLoginPassword,std::string strMainPath,std::stringstrSubPath,std::string strLocalFilePath,std::string strRomuteFileName,bool bIsBinary){std::string strCommandFile = strMainPath;strCommandFile = "http://";strCommandFile = strUuid;strCommandFile = "-command.tmp";FILE * pCommandFile = fopen(strCommand.c_str(),"w ");std::string strFileName = "";char *pSrcFilePath = (char *)strLocalFilePath.c_str();char *pFindPos = strrchr(pSrcFilePath,"/");if(pFindPos == NULL){pFindPos = strrchr(pSrcFilePath,"\\");}if(pFindPos != NULL){strFileName = strLocalFilePath.substr((pFindPos-pSrcFilePath) 1,strLocalFilePath.size()-((pFindPos-pSrcFilePath) 1));}if(pCommandFile != NULL){fprintf(pCommandFile,"open %s %d\n",strIp.c_str(),nPort);fprintf(pCommandFile,"USER %s\n",strLoginUsername.c_str());fprintf(pCommandFile,"%s\n",strLoginPassword.c_str());//create directoryfprintf(pCommandFile,"mkdir %s\n",strMainPath.c_str());fprintf(pCommandFile,"cd %s\n",strMainPath.c_str());fprintf(pCommandFile,"mkdir %s\n",strSubPath.c_str());fprintf(pCommandFile,"cd %s\n",strSubPath.c_str());if(bIsBinary){fprintf(pCommandFile,"binary\n");}else{fprintf(pCommandFile,"ascii\n");}fprintf(pCommandFile,"prompt off\n");fprintf(pCommandFile,"delete %s\n",strRomuteFileName.c_str());fprintf(pCommandFile,"put %s\n",strLocalFilePath.c_str());//renameif(strRomuteFileName.size() > 0 && strFileName != strRomuteFileName){fprintf(pCommandFile,"rename %s %s\n",strFileName.c_str(),strRomuteFileName.c_str());}fprintf(pCommandFile,"quit\n");fclose(pCommandFile);std::string strParameter = "-n -s:" strCommandFile;SHELLEXECUTEINFO shExecInfo = {0};shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;shExecInfo.hwnd = NULL;shExecInfo.lpVerb = NULL;shExecInfo.lpFile = "ftp.exe";shExecInfo.lpParameters = strParameter;shExecInfo.lpDirectory = NULL;shExecInfo.nShow = SW_HIDE;shExecInfo.hInstApp = NULL;ShellExecuteEx(&shExecInfo);WaitForSingleObject(shExecInfo.hProcess,INFINITE);DeleteFile(strCommandFile.c_str());return true;}else{return false;}}

本文就為大家講解到這里,希望對(duì)大家有所幫助。

關(guān)鍵詞:

X 關(guān)閉

財(cái)經(jīng) 查看更多
安陽曹操墓將于2022年5月正式對(duì)公眾開放
時(shí)間·2021-12-29    來源·中新網(wǎng)
為什么這次寒潮南方降雪這么明顯?
時(shí)間·2021-12-29    來源·新華社
山西絳縣6名失蹤者全部遇難 當(dāng)?shù)兀阂蚜刚{(diào)查
時(shí)間·2021-12-29    來源·中新網(wǎng)

X 關(guān)閉