这是我目前的代码,但它没有做任何事情。我还希望它在下载完成后打开do.bat
#include <cstdlib>
#include <iostream>
#include <wininet.h>
using namespace std;
int main(int argc, char *argv[])
{
HINTERNET hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0); // Initialization for WinInet Functions
HINTERNET hFtpSession = InternetConnect(hInternet,"server",INTERNET_DEFAULT_FTP_PORT,"user","pass", INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0); // Starts a session in this case an FTP session
FtpGetFile(hInternet,"do.bat","C:\\do.bat",FALSE,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_ASCII,0);
InternetCloseHandle(hFtpSession); // Close hFtpSession
InternetCloseHandle(hInternet); // Close hInternet
system("PAUSE");
return EXIT_SUCCESS;
}
答案 0 :(得分:1)
FtpGetFile(hInternet,&#34; do.bat&#34;,&#34; C:\ do.bat&#34;,FALSE,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_ASCII,0);
与
<强> FtpGetFile(hFtpSession,&#34; do.bat&#34;&#34; C:\ do.bat&#34;,FALSE,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_ASCII,0); 强>
#include <cstdlib>
#include <iostream>
#include <wininet.h>
using namespace std;
int main(int argc, char *argv[])
{
HINTERNET hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0); // Initialization for WinInet Functions
HINTERNET hFtpSession = InternetConnect(hInternet,"ftp.drivehq.com",INTERNET_DEFAULT_FTP_PORT,"merzu","8067-MPSE", INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0); // Starts a session in this case an FTP session
FtpGetFile(hFtpSession,"do.bat","do.bat",TRUE,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_ASCII,0);
InternetCloseHandle(hFtpSession); // Close hFtpSession
InternetCloseHandle(hInternet); // Close hInternet
system("PAUSE");
return EXIT_SUCCESS;
}