使用ASP.net c#上传文件到SFTP
本文关键字:文件 SFTP ASP net 使用 | 更新日期: 2023-09-27 18:05:41
我正在尝试使用c#与第三方库(Tamir.SharpSsh)上传文件到SFTP。
我得到下面的错误。请建议。
System.Net.Sockets.SocketException: The requested name is valid, but no data of the requested type was found
at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
at System.Net.Dns.GetHostByName(String hostName)
at Tamir.SharpSsh.java.net.Socket..ctor(String host, Int32 port)
at Tamir.SharpSsh.jsch.Util.createSocket(String host, Int32 port, Int32 timeout)
下面是我的代码:
using Tamir.SharpSsh;
using Tamir.Streams;
using Tamir.SharpSsh.jsch;
调用这个函数:
private static void UploadFileToFTP(string file_name)
{
string sftp_Servername = "https://xxx.ftpxxx.com/";
string sftp_username = "username";
string sftp_password = "password";
int sftp_port = 22;
Sftp SFTP = new Sftp(sftp_Servername, sftp_username, sftp_password);
SFTP.Connect();
SFTP.Put(file_name, sftp_Servername);
}
谢谢,
Mugundhan R
以上工作正常…但是突然这个错误出现了
System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 46.16.160.16:22
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
at Tamir.SharpSsh.java.net.Socket..ctor(String host, Int32 port)
at Tamir.SharpSsh.jsch.Util.createSocket(String host, Int32 port, Int32 timeout)
变化
string sftp_Servername = "https://xxx.ftpxxx.com/";
string sftp_Servername = "xxx.ftpxxx.com";