-1
我试图下载名为“public_html”的文件夹,但它没有在我的程序中做任何事情,这里是我的代码。C++ FTP WinINet,无法从FTP服务器下载文件夹
int main(){
cerr<<"Hello"<<endl;
string spath = "C:/Users/"+GetUser()+"/Desktop";
spath += str;
LPCSTR path = spath.c_str();
HINTERNET hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); // Initialization for WinInet Functions
if (!hInternet) { cerr<<"error code is "<<GetLastError()<<"\n";
system("pause");
return 1; }
// Starts a session in this case an FTP session
HINTERNET hFtpSession = InternetConnect(hInternet,IP,INTERNET_DEFAULT_FTP_PORT,User,Pass, INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0);
if(!hFtpSession) {
InternetCloseHandle(hInternet);
cerr<<"error code is "<<GetLastError()<<"\n";
system("pause");
return 2;
}
FtpGetFile(hFtpSession, str, path, false, NULL, FTP_TRANSFER_TYPE_BINARY, NULL);
// Uploads the file C:\\Test.txt onto the FTP server as Test.txt
InternetCloseHandle(hFtpSession); // Close hFtpSession
InternetCloseHandle(hInternet); // Close hInternet
return 0;
}
这个工程,当我一次下载单个文件,但不是当我做它与文件夹。为什么不?你最终没有理解什么是真正发生的事情你的机器上,并不能很容易地确定哪些功能:BTW
LPCSTR str = "/public_html";
因为这不是FTP的工作原理。 –
@ MahmoudAl-Qudsi不只是这么说,你可以解释我为什么或什么做错了,或者如何解决它。 : – user2635579
因为它不是[FTP标准](http://www.ietf.org/rfc/rfc959.txt)的一部分。您必须输入目录并手动递归获取所有文件。 –