C ++ WinINET FtpPutFile错误代码3

问题描述 投票:1回答:1

我遇到了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.也许是因为我使用了错误的路径语法?

c++ windows path wininet
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.