上传目录

时间:2012-02-26 01:10:20

标签: c++ ftp directory uploading

如何使用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;
}

1 个答案:

答案 0 :(得分:0)

你不能直接“上传”目录;您需要使用FtpCreateDirectory()创建目录,然后遍历本地目录中的所有文件,并在每个文件上调用FtpPutFile()

如果您需要一种获取目录中文件列表的方法,可以使用Boost.Filesystem。查找directory_iteratorrecursive_directory_iterator类。