C++ WinInet FtpPutFile() Returning Error Code 5 (Access Is Denied)

1

I have a basic sample I'm trying that is meant to upload a text file to an FTP server. The FTP server resides locally on my Windows 10 machine. I'm running an IIS FTP Site. When I connect through an FTP client with the same information I provide my C++ program I am able to add test.txt to the FTP Site. No authentication issues, no file extension filtering issues, no connection/firewall issues.

When I run my C++ program the error code returned is 5 (Access Is Denied). I am sure there is something right in front of me I'm not seeing. The user being used to connect in the code is an administrator. I also changed it to my own user that installed IIS and created the FTP directory, but same problem. Here is my code:

main:

int main()
{
    const std::string PathBase = "E:/Test";
    const std::string FileName = "test.txt";
    file_upload(PathBase, FileName);
}

string_to_wstring:

std::wstring string_to_wstring(const std::string& text)
{
    return std::wstring(text.begin(), text.end());
}

file_upload:

BOOL file_upload(std::string FilePath, std::string FileName)
{
    std::wstring tmpBase = string_to_wstring(FilePath);
    std::wstring tmpName = L"/" + string_to_wstring(FileName);
        HINTERNET hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
        HINTERNET hFtpSession = InternetConnect(hInternet, L"192.168.65.1", 21, L"testuser", L"password", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
        BOOL Transfer = FtpPutFile(hFtpSession, &tmpBase[0], &tmpName[0], 0x00000002, 0);
        if (!Transfer)
        {
            std::cout << "Failed to upload" << std::endl;
            std::cout << "Error: " << GetLastError() << std::endl;
            std::cout << "Response Info: " << InternetGetLastResponseInfoW << std::endl;
        }

        InternetCloseHandle(hFtpSession);
        InternetCloseHandle(hInternet);

    return 0;
}

My output:

Failed to upload
Error: 5
Response Info: 00007FFFC349CB60

Any help is much appreciated!

c++
ftp
asked on Stack Overflow Oct 19, 2019 by LJR135

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0