2015-07-11 169 views
-2

我在使用C++中的wininet.h作爲測試上傳文件時遇到問題。 這不是我的代碼,但在我開始學習之前,我想確保它能正常工作。 它完美運行並按照預期關閉,但我看着我的ftp,並且我的文件沒有出現,意味着它不會以某種方式傳輸。 有人可以給我一個解釋,爲什麼發生這種情況?C++ FTP上傳

這裏是我學習過的代碼:

#include <windows.h> 
#include <wininet.h> 
#include <iostream> 
#include <stdio.h> 
#pragma comment(lib, "wininet.lib") 


int main() 

{ 

    HINTERNET hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); // Initialization for WinInet Functions 

    if (!hInternet) { return 1; } 

    // Starts a session in this case an FTP session 

    HINTERNET hFtpSession = InternetConnect(hInternet, "ftp.byethost3.com", INTERNET_DEFAULT_FTP_PORT, "username", "password", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0); 

    if (!hFtpSession) { 

     InternetCloseHandle(hInternet); 

     return 1; 

    } 

    FtpPutFile(hFtpSession, "C://Users//Programming//Downloads//test.txt", "test.txt", FTP_TRANSFER_TYPE_BINARY, 0); 

    // Uploads the file C:\\Test.txt onto the FTP server as Test.txt 



    InternetCloseHandle(hFtpSession); // Close hFtpSession 

    InternetCloseHandle(hInternet); // Close hInternet 

    return 0; 

} 

回答