我是新手编码并且无法尝试将名为“test.txt”的文本文件上传到ftp服务器,这是我的代码:
void nointernet()
{
std::cout << "No internet connection." << std::endl;
}
int upload()
{
HINTERNET hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (!hInternet)
{
nointernet();
}
HINTERNET hFtpSession = InternetConnect(hInternet, "FTPHOST", INTERNET_DEFAULT_FTP_PORT, "FTPUSER", "FTPPASS", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
if (!hFtpSession)
{
InternetCloseHandle(hInternet);
nointernet();
}
FtpPutFile(hFtpSession, "D:/test.txt", "test.txt", FTP_TRANSFER_TYPE_BINARY, 0);
std::cout << "File Uploaded." << std::endl;
InternetCloseHandle(hFtpSession);
InternetCloseHandle(hInternet);
return 0;
}
int main() {
upload();
return 0;
}
欢迎任何反馈。
答案 0 :(得分:1)
很抱歉打扰我解决了这里的代码,如果有人有兴趣:
#include <wininet.h>
#pragma comment(lib, "Wininet")
int upload()
{
HINTERNET hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
HINTERNET hFtpSession = InternetConnect(hInternet, "HOST", INTERNET_DEFAULT_FTP_PORT, "USER", "PASS", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
FtpPutFile(hFtpSession, "C:/test.txt", "/test.txt", FTP_TRANSFER_TYPE_BINARY, 0);
std::cout << "File Uploaded." << std::endl;
InternetCloseHandle(hFtpSession);
InternetCloseHandle(hInternet);
return 0;
}
int main() {
upload();
return 0;
}