Internet Connect在尝试连接到SFTP服务器时返回错误12002
InternetConnect returns error 12002 when attempting to connect to a sftp server
给定以下代码,该代码应连接到sftp
服务器,并在该服务器中打印第一个文件的名称。看起来它返回了错误12002,这意味着请求时间已计时。我尝试使用2个不同的服务器运行它。我的代码中有根本上有问题吗?
#include "stdafx.h"
#include <Windows.h>
#include <Wininet.h>
#include <iostream>
using namespace std;
#pragma comment(lib, "wininet.lib")
int main()
{
HINTERNET hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hInternet == NULL)
{
_tprintf(_T("An error has occured while trying to open the internet connectionn"));
return 1;
}
HINTERNET hFTP = InternetConnect(
hInternet,
L"test.rebex.net", // this is a sftp server publicly available
22,
L"demo",
L"password",
INTERNET_SERVICE_FTP,
INTERNET_FLAG_PASSIVE,
0
);
if (hFTP == NULL)
{
cout << GetLastError() << endl;
_tprintf(_T("Couldn't connect to the ftp servern"));
return 1;
}
_tprintf(_T("%dn"), hFTP);
WIN32_FIND_DATA fd;
FtpFindFirstFile(hFTP, L".", &fd, INTERNET_FLAG_RELOAD, NULL);
_tprintf(_T("%s"), fd.cFileName);
InternetCloseHandle(hFTP);
InternetCloseHandle(hInternet);
return 0;
}
sftp(SSH上方的FTP)与FTP(ftp over ssl)非常不同,这可能是您想要的。
但是,无论哪种方式,Wininet根本不支持SFTP或FTPS(INTERNET_FLAG_SECURE
标志仅支持HTTPS)。
您将必须使用另一个支持SFTP/FTP的FTP库。
相关文章:
- UDP 服务器无法发送回复,发送返回 -1,errno 为 22
- TCP套接字(客户端-服务器)recv()返回-1值
- 关于C++套接字,为什么服务器总是返回相同的结果?
- C++ 套接字 read() 有时在连接到服务器时返回 -1
- boost::asio http 服务器无法向 Postman 返回有效响应
- TCP 服务器/客户端:客户端 recv() 返回空白缓冲区
- C 将NTP服务器返回的时间转换为字符串
- Internet Connect在尝试连接到SFTP服务器时返回错误12002
- MFC ole服务器移植到较新版本 - afxgetThread返回null
- 将文件的数据从服务器返回到客户端 - reg
- NTP服务器总是返回相同的错误日期(窗口)
- Winsock send()总是在服务器中返回错误10057
- 当服务器不可访问时,curl_easy_performer返回-1
- 调用 boost::asio::tcp::socket 方法后async_read处理程序在服务器中返回错误
- UNIX域套接字C++服务器无法将数据返回到客户端
- Apache Thrift:在列表前使用"optional"时,C++服务器似乎没有正确返回它
- 由于从客户端启动守护程序应用程序,服务器端口无法返回侦听并处于关闭等待状态
- 服务器接收到所有数据,但HttpSendRequest在客户端返回FALSE 12002
- RPC服务器返回结果char将得到段错误
- 从进程外COM服务器返回接口指针的正确方式是什么