我对WinINET的FtpPutFile()
函数有问题。
代码如下:
#include <Windows.h>
#include <wininet.h>
#include <iostream>
#pragma comment(lib, "Wininet")
using namespace std;
void FileSubmit()
{
HINTERNET hInternet;
HINTERNET hFtpSession;
hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (hInternet == NULL)
{
cout << "Error: InternetOpen = " << GetLastError() << endl;
}
else
{
hFtpSession = InternetConnect(hInternet, "host", INTERNET_DEFAULT_FTP_PORT, "name", "pass", INTERNET_SERVICE_FTP, 0, 0);
if (hFtpSession == NULL)
{
cout << "Error: InternetConnect = " << GetLastError() << endl;
}
else
{
if (FtpPutFile(hFtpSession, "C:\Utenti\Luca\Desktop\pop.txt", "pop.txt", FTP_TRANSFER_TYPE_BINARY, 0))
cout << "File send" << endl;
else
cout << "Error: FtpPutFile = " << GetLastError() << endl;
InternetCloseHandle(hFtpSession);
}
InternetCloseHandle(hInternet);
}
}
int main()
{
FileSubmit();
return 0;
}
该程序确实连接到互联网,但似乎无法发送文件。GetLastError()
返回错误代码 3。 也许是因为我使用了错误的路径语法?
GetLastError
返回 3 表示找不到路径:https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85(.aspx
尝试从程序工作目录传递文件。