这是我的代码到目前为止,它下载了一个文件。
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;
}
我想让这个下载整个目录,为此我需要获取文件列表。有帮助吗?还有,任何例子?提前致谢! :)