【发布时间】:2013-08-29 07:02:49
【问题描述】:
我正在尝试下载名为“public_html”的文件夹,但它在我的程序中没有执行任何操作,这是我的代码。
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;
}
这在我一次下载单个文件时有效,但在我使用文件夹时无效。为什么不?顺便说一句
LPCSTR str = "/public_html";
【问题讨论】:
-
因为 FTP 不是这样工作的。
-
@MahmoudAl-Qudsi 您可以解释为什么或我做错了什么,或者如何解决它。 :
-
因为它不是FTP standard 的一部分。您必须进入目录并手动递归获取所有文件。
-
如何获取我输入的目录中所有文件和目录的列表?
-
我确定有functions for that。