I want to connect to SFTP to download files from there. I can able to login into SFTP by using the credential via website and Command Prompt (using ftp command) as well. Now, I want to connect it from my .Net code using specific credential.
I am using SSH.NET with version 2020.0.1 and .Net Core Runtime version 3.1.18 and .Net Core SDK version 3.1.412 and OS is Windows (10.0.17763) 64 bit.
While trying to connect with SFTP via .Net Framework, I can doing it comfortably using same DLL version downloaded from NuGet. Now, when I am using same piece of code for .Net Core project, it is throwing exception. I have downloaded same package version from NuGet for .Net Core.
Below is my code:
public void Connect()
{
string host = "xxxx.xx.xxx";
int port = xx;
string userid = "xxxx";
string password = "xxxx";
try
{
Renci.SshNet.SftpClient client = new Renci.SshNet.SftpClient(host, port, userid, password);
if (!client.IsConnected)
{
client.ConnectionInfo.Timeout = TimeSpan.FromMinutes(1);
client.Connect();
Console.WriteLine("SFTP client connected successfully");
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
The exception message that I am getting when I am using .Net Core is as below:
Accessing a hash algorithm by manipulating the HashName property is not supported on this platform. Instead, you must instantiate one of the supplied subtypes (such as HMACSHA1.)
In which place I am doing mistake? Any help would be highly appreciated !!
After lots of workaround, I found the solution.
SSH.NET has dependency on SshNet.Security.Cryptography.
SSH.NET (version 2020.0.1) refers SshNet.Security.Cryptography with version 1.3.0 whereas SSH.NET (version 2016.1.0) refers SshNet.Security.Cryptography with version 1.2.0.
I have updated SSH.NET version from 2020.0.1 to 2016.1.0.
It might happen that there is some backward compatibility issue. And for that, by lowering the version, it is working.
Now, the above code works perfectly fine with .NET Framework and .NET Core as well. The above error is not appearing while connecting with SFTP.