需要FtpGetFile的例子,不能正常工作

时间:2014-04-20 11:19:20

标签: c++ windows ftp download wininet

这是我目前的代码,但它没有做任何事情。我还希望它在下载完成后打开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;
}

1 个答案:

答案 0 :(得分:1)

哇,不,再也不用了,只是一个noobie错误。我需要更换

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;
}