C++;我不能上传文件到FTP服务器 我想用C++代码把一个文件上传到我的FTP服务器,我可以用FielZILA来FTP服务器。p> 当我运行C++代码时,它会给我一个输出“3”错误(GETLASTReRelo()函数,将这个值返回到ftpPutfIE()函数 #pragma注释(lib,“wininet.lib”) #包括 #包含//用于上载文件功能 #包括 使用名称空间std; int main() { 提示网提示; 提示=InternetOpen(“FTP”,INTERNET\u打开\u类型\u预配置,0,0,INTERNET\u标志\u异步); hftp=InternetConnect(提示,“我的IP地址”、INTERNET\u默认\u FTP\u端口、“我的姓名”、“我的通行证”、INTERNET\u服务\u FTP,0,0); 如果(!FtpPutFile(hftp,“C://Users//Elliot//Desktop//log.txt”,“//log.txt”,FTP\u TRANSFER\u TYPE\u BINARY,0)) { cout

C++;我不能上传文件到FTP服务器 我想用C++代码把一个文件上传到我的FTP服务器,我可以用FielZILA来FTP服务器。p> 当我运行C++代码时,它会给我一个输出“3”错误(GETLASTReRelo()函数,将这个值返回到ftpPutfIE()函数 #pragma注释(lib,“wininet.lib”) #包括 #包含//用于上载文件功能 #包括 使用名称空间std; int main() { 提示网提示; 提示=InternetOpen(“FTP”,INTERNET\u打开\u类型\u预配置,0,0,INTERNET\u标志\u异步); hftp=InternetConnect(提示,“我的IP地址”、INTERNET\u默认\u FTP\u端口、“我的姓名”、“我的通行证”、INTERNET\u服务\u FTP,0,0); 如果(!FtpPutFile(hftp,“C://Users//Elliot//Desktop//log.txt”,“//log.txt”,FTP\u TRANSFER\u TYPE\u BINARY,0)) { cout,c++,file-upload,ftp,C++,File Upload,Ftp,错误消息很清楚。文件不在那里,没有要发送的内容。在继续使用internet功能之前,您可以使用std::ifstream轻松检查文件路径 使用FtpSetCurrentDirectory设置目标目录。在本例中,我使用了“public\u html”,可能您的服务器不同 #include <windows.h> #include <wininet.h> #include <iostream> #include <string> #include &

错误消息很清楚。文件不在那里,没有要发送的内容。在继续使用internet功能之前,您可以使用
std::ifstream
轻松检查文件路径

使用
FtpSetCurrentDirectory
设置目标目录。在本例中,我使用了
“public\u html”
,可能您的服务器不同

#include <windows.h>
#include <wininet.h> 
#include <iostream>
#include <string>
#include <fstream>

#pragma comment (lib,"wininet.lib")

using namespace std;

int main()
{
    string file = "C:\\path.txt";
    string site = "www.site.com";
    string user = "username";
    string pass = "password";

    if (!ifstream(file))
    {
        cout << "no file\n";
        return 0;
    }

    HINTERNET hint = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
    HINTERNET hftp = InternetConnect(hint, site.c_str(), INTERNET_DEFAULT_FTP_PORT,
        user.c_str(), pass.c_str(), INTERNET_SERVICE_FTP, 0, 0);

    if (FtpSetCurrentDirectory(hftp, "public_html"))
    {
        if (!FtpPutFile(hftp, file.c_str(), "log.txt", FTP_TRANSFER_TYPE_BINARY, 0))
        {
            cout << "FAIL!" << endl;
            cout << GetLastError() << endl;
        }
        else
        {
            cout << "file sended !";
        }
    }
    InternetCloseHandle(hftp);
    InternetCloseHandle(hint);
    return 0;
}
#包括
#包括
#包括
#包括
#包括
#pragma注释(lib,“wininet.lib”)
使用名称空间std;
int main()
{
string file=“C:\\path.txt”;
string site=“www.site.com”;
字符串user=“username”;
字符串pass=“password”;
if(!ifstream(文件))
{

cout
C://Users//Elliot//Desktop//log.txt
在windows下指定文件名是一种奇怪的方式,我本以为
C:\\Users\\Elliot\\Desktop\\log.txt来自马口:我改为“\\”仍然不起作用…我还能做什么?不确定哪个路径会冒犯它,本地文件路径还是远程路径,或者…fud。我想我看到了。你不需要逃避正斜杠。试试“/log.txt”。把
/
放到远程文件名上:
FtpPutFile(hftp,“C:\\Users\\Elliot\\Desktop\\log.txt”,“log.txt”,FTP\u TRANSFER\u TYPE\u BINARY,0)
FtpPutFile()
将文件上载到远程服务器的当前工作目录,因此如果要上载到特定文件夹,请先调用
FtpSetCurrentDirectory()
#include <windows.h>
#include <wininet.h> 
#include <iostream>
#include <string>
#include <fstream>

#pragma comment (lib,"wininet.lib")

using namespace std;

int main()
{
    string file = "C:\\path.txt";
    string site = "www.site.com";
    string user = "username";
    string pass = "password";

    if (!ifstream(file))
    {
        cout << "no file\n";
        return 0;
    }

    HINTERNET hint = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
    HINTERNET hftp = InternetConnect(hint, site.c_str(), INTERNET_DEFAULT_FTP_PORT,
        user.c_str(), pass.c_str(), INTERNET_SERVICE_FTP, 0, 0);

    if (FtpSetCurrentDirectory(hftp, "public_html"))
    {
        if (!FtpPutFile(hftp, file.c_str(), "log.txt", FTP_TRANSFER_TYPE_BINARY, 0))
        {
            cout << "FAIL!" << endl;
            cout << GetLastError() << endl;
        }
        else
        {
            cout << "file sended !";
        }
    }
    InternetCloseHandle(hftp);
    InternetCloseHandle(hint);
    return 0;
}