Market Data Unfair Advantage Posting Status Robert 2016

How to download files from SFTP in C#

First you must install the SSH.Net library from NuGet. Add the .dll as a reference to your project.

Code Snippet
  1. using System.IO;
  2. using Renci.SshNet;
  3. using Renci.SshNet.Common;
  4. using Renci.SshNet.Sftp;
  5.  
  6. String Host = “ftp.csidata.com”;
  7. int Port = 22;
  8. String RemoteFileName = “TheDataFile.txt”;
  9. String LocalDestinationFilename = “TheDataFile.txt”;
  10. String Username = “yourusername”;
  11. String Password = “yourpassword”;
  12.  
  13. using (var sftp = new SftpClient(Host, Port, Username, Password))
  14. {
  15.     sftp.Connect();
  16.  
  17.     using (var file = File.OpenWrite(LocalDestinationFilename))
  18.     {
  19.         sftp.DownloadFile(RemoteFileName, file);
  20.     }
  21.  
  22.     sftp.Disconnect();
  23. }