我正在尝试下载名为“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";