我有这个简单的代码将文件上传到服务器,但似乎它不起作用,不上传任何文件(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.
答案 0 :(得分:1)
GetLastError()为FtpPutFile返回ERROR_SHARING_VIOLATION(32),这可能意味着“c:\ stories.txt”的打开句柄会阻止读取共享。如果在程序中打开此文件,则需要在CreateFile调用中允许读取共享或关闭所有阻止共享的打开句柄,以便FtpPutFile可以打开文件。