问题描述
我现在一直在寻找2个小时,我似乎无法弄清楚如何用FTP服务器上传文件。
我会更喜欢使用WinINet,因为我是C ++和Microsoft Visual Studio的新手(我不是新手,只是对C ++)
我真正需要的是如何使用FTP服务器上传文件的工作示例。在过去的2个小时里,我一直在网上,我找不到任何东西。
我尝试了很多不同的库和东西,但无论如何,如果您想分享您使用FTP上传C ++文件的知识,链接或体验,感谢-Alex Benoit
>想出来。这是我使用的代码
#include< wininet.h>
#pragma comment(lib,Wininet)
void FileSubmit()
{
HINTERNET hInternet;
HINTERNET hFtpSession;
hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
if(hInternet == NULL)
{
cout<< 错误:<< GetLastError函数();
hFtpSession = InternetConnect(hInternet,server,INTERNET_DEFAULT_FTP_PORT,user,pass,INTERNET_SERVICE_FTP,0,0);
if(hFtpSession == NULL)
{
cout<< 错误:<< GetLastError函数();
}
else
{
if(!FtpPutFile(hFtpSession,C://file.txt,/file.txt,FTP_TRANSFER_TYPE_BINARY,0))
{
cout<< 错误:<< GetLastError函数();
}
}
}
}
I have been searching for 2 hours now, and I can't seem to figure out how to simply upload a file with an FTP server.
I'd prefer to use WinINet, since I'm new to C++ and Microsoft Visual Studio (I'm not new to programming, just to C++)
All I really need is a working example of how to upload a file with an FTP server. I've been all over the web for the last 2 hours, and I can't find anything.
I've tried a lot of different libraries and stuff, but none seem to work, and a lot are outdated.
Anyways, if you'd share your knowledge, links, or experience about using FTP to upload a file with C++, I'd really appreciate it.
Thanks -Alex Benoit
Figured it out. Here's the code I'm using
#include <wininet.h>
#pragma comment(lib, "Wininet")
void FileSubmit()
{
HINTERNET hInternet;
HINTERNET hFtpSession;
hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (hInternet == NULL)
{
cout << "Error: " << GetLastError();
}
else
{
hFtpSession = InternetConnect(hInternet, "server", INTERNET_DEFAULT_FTP_PORT, "user", "pass", INTERNET_SERVICE_FTP, 0, 0);
if (hFtpSession == NULL)
{
cout << "Error: " << GetLastError();
}
else
{
if (!FtpPutFile(hFtpSession, "C://file.txt", "/file.txt", FTP_TRANSFER_TYPE_BINARY, 0))
{
cout << "Error: " << GetLastError();
}
}
}
}
这篇关于C ++使用WinINet上传到FTP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!