0

我有这个简单的代码可以将文件上传到服务器,但它似乎不起作用,没有上传任何文件(FtpPutFile 返回 0)。我正在使用 FileZilla Server,这是我的代码和 FileZilla 所说的:

void upload()
{
    hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    hFtpSession = InternetConnect(hInternet,"127.0.0.1",INTERNET_DEFAULT_FTP_PORT,"vbx","pass",INTERNET_SERVICE_FTP, 0,0 );
    FtpPutFile(hFtpSession, "c:\\stories.txt", "e:\\text.txt", FTP_TRANSFER_TYPE_BINARY, 0);
    InternetCloseHandle(hFtpSession);
    InternetCloseHandle(hInternet);
}

(000011)3/27/2011 0:01:53 AM - (not logged in) (127.0.0.1)> USER vbx
(000011)3/27/2011 0:01:53 AM - (not logged in) (127.0.0.1)> 331 Password required for vbx
(000011)3/27/2011 0:01:53 AM - (not logged in) (127.0.0.1)> PASS *******
(000011)3/27/2011 0:01:53 AM - vbx (127.0.0.1)> 230 Logged on
(000011)3/27/2011 0:01:53 AM - vbx (127.0.0.1)> disconnected.  

谢谢你。

编辑:GetLastError() returns: The process cannot access the file because it is being used by another process.

4

1 回答 1

1

GetLastError() 为 FtpPutFile 返回 ERROR_SHARING_VIOLATION (32),这可能意味着“c:\stories.txt”的打开句柄阻止了读取共享。如果您在程序中打开了此文件,则需要在 CreateFile 调用中允许读取共享或关闭所有阻止共享的打开句柄,以便 FtpPutFile 可以打开该文件。

于 2011-03-26T22:44:58.240 回答