2012-02-26 86 views
0

如何上傳使用FtpPutFile功能或者這一切的目錄的目錄是我的代碼:上傳目錄

void FileSubmit(path ToUpload) 
{ 
    HINTERNET hInternet; 
    HINTERNET hFtpSession; 
    hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0); 

    if (hInternet == NULL) cout << ("No Internet Connection..\n"); 
    else cout << ("Internet Connection Established\n"); 

    hFtpSession = InternetConnect(hInternet,"host",INTERNET_DEFAULT_FTP_PORT, "user","pass", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE,0); 
    if (!hFtpSession) cout << ("Error in the FTP connection..\n"); 
    else 
    { 
     cout <<("FTP Connection Established!\n"); 
     FtpPutFile(hFtpSession, "D://test//*.doc", ToUpload.string().c_str(), FTP_TRANSFER_TYPE_ASCII, INTERNET_FLAG_PASSIVE); 
     if (!FtpPutFile(hFtpSession, "D://test//*.doc", ToUpload.string().c_str(), FTP_TRANSFER_TYPE_ASCII, INTERNET_FLAG_PASSIVE)) 
     cout <<("File Transfer Failed..\n"); 
     else cout << ("The file was sent..\n"); 
     InternetCloseHandle(hFtpSession); 
     InternetCloseHandle(hInternet); 
    } 
} 


int main() 
{ 
FileSubmit(destination); 
return 0; 
} 

回答

0

你不能「上傳」目錄直接;您需要創建FtpCreateDirectory()的目錄,然後遍歷本地目錄中的所有文件,並在每個文件中調用FtpPutFile()

如果您需要一種獲取目錄中文件列表的方法,您可以使用Boost.Filesystem。尋找directory_iteratorrecursive_directory_iterator類。

+0

我不需要在主機上創建一個目錄,但是如何迭代本地目錄中的所有文件 – pourjour 2012-02-26 01:15:58

+0

@pourjour我已經更新了我的答案。如果你願意的話,在Windows API中會有一些東西需要做,但是你必須自己來看看。 – spencercw 2012-02-26 01:17:14