-1

I am using the SharpSsh to transfer the file to server using SFTP through ASP.NET.

Below is my source code. But I am getting the error!

    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();
        }
    }

When i try to run the code i am getting the following exception please help me how to fix this exeception.

    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)
mason
  • 31,774
  • 10
  • 77
  • 121

1 Answers1

0

The sftpHost argument of Tamir.SharpSsh.Sftp constructor takes an IP address or a host name, not a URL. And even if it took a URL, it would be sftp://, not ftp://.

So it should be:

Sftp oSftp = new Sftp("22.00.333.444", _UserName, _Password);

But of course 22.00.333.444 is not a valid IP address.


And I strongly discourage you from using SharpSSH. It's a dead project.

For alternatives, see:

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992