C ++ WinINET FtpPutFile错误代码3

时间:2018-05-04 19:48:02

标签: c++ windows path wininet

我遇到了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;

}

程序确实连接到Internet,但似乎无法发送文件。 GetLastError()返回错误代码3.也许是因为我使用了错误的路径语法?

1 个答案:

答案 0 :(得分:0)

GetLastError返回3表示路径未找到:https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx

尝试从程序工作目录传递文件。