我正在使用SharpSsh通过ASP.NET使用SFTP将文件传输到服务器。如何使用SFTP通过ASP.NET上传服务器中的文件?
以下是我的源代码。但是我得到错误!
using System.Collections;
using System.Threading;
using System.IO;
using Tamir.SharpSsh;
using Tamir.Streams;
protected void btnUpload_Click(object sender, EventArgs e)
{
if (fuUploadFile.HasFile)
{
string _ftpURL = "ftp://22.00.333.444/";
string _UserName = "admin";
string _Password = "admin123";
int _Port = 22;
string _ftpDirectory = "/TestFTP";
string LocalDirectory =
Server.MapPath(fuUploadFile.PostedFile.FileName);
string FileName = fuUploadFile.FileName;;
Sftp oSftp = new Sftp(_ftpURL, _UserName, _Password);
oSftp.Connect(_Port);
oSftp.Put(LocalDirectory , _ftpDirectory + "/" + FileName);
oSftp.Close();
}
}
当我尝试运行代码时我收到以下异常请帮助我如何解决这个问题。
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)
你混淆那个IP?因为如果不是,它是无效的。 –
另外,我所看到的所有例子都没有'ftp://'前缀。 –
你为什么要在所有变量前面加上下划线?这不符合正常的C#约定。 – mason