6

Is there a way to download a file from a sftp server with .net core 3.1 ?

I found various answers which are all outdated. (for example, ssh.net cannot be found anymore)

How is the current status in this topic?

askolotl
  • 964
  • 1
  • 13
  • 27
  • https://stackoverflow.com/questions/48432921/does-net-core-2-0-have-sftp-client – rene Apr 22 '20 at 09:31
  • @rene your link is 2 years old, and is about .net core 2.0, not 3.1 – askolotl Apr 22 '20 at 11:01
  • Sure, I just wanted to give some pointers as you didn't include which outdated answers you already saw. SSH.Net is indeed old but that goes back to .Net 2.0 if memory serves well. – rene Apr 22 '20 at 11:45
  • I have found SSH.NET meanwhile, but it is NOT compatible to .net core unfortunately. – askolotl Apr 22 '20 at 16:05
  • 1
    There is a [develop branch of SSH.Net](https://github.com/sshnet/SSH.NET) that is [setup to work with .Net Core 3.1](https://github.com/sshnet/SSH.NET/issues/355#issuecomment-605509043) but [not yet published](https://github.com/sshnet/SSH.NET/issues/636). Unfortunately that project was delayed for a while. Perhaps you could try the develop branch? – NetMage Apr 23 '20 at 00:08
  • @NetMage **thanks a lot**, I will give it a try! Maybe I can even support the project. – askolotl Apr 23 '20 at 08:11

1 Answers1

2

There is an updated version of SSH.net called Neon.SSh.Net https://www.nuget.org/packages/Neon.SSH.NET/

works in the same way as the old version from Renci.

...
var client = new SftpClient(host,port,username,password);
    client.Connect();
    using (Stream fileStream = File.OpenWrite("c:\\temp\\file.tmp"))
    { 
          _client.DownloadFile(ftpFilePath, fileStream);
    }
...
Thorarins
  • 1,836
  • 16
  • 21