The server allows only 2 concurrent sessions per user. Also there is a 2 minute timeout for idle connections. Your code must account for these otherwise the server will disconnect the session.
First you must install the SSH.Net library from NuGet. Add the .dll as a reference to your project.
Code Snippet
- using System.IO;
- using Renci.SshNet;
- using Renci.SshNet.Common;
- using Renci.SshNet.Sftp;
- String Host = “ftp.csidata.com”;
- int Port = 22;
- String RemoteFileName = “TheDataFile.txt”;
- String LocalDestinationFilename = “TheDataFile.txt”;
- String Username = “yourusername”;
- String Password = “yourpassword”;
- using (var sftp = new SftpClient(Host, Port, Username, Password))
- {
- sftp.Connect();
- using (var file = File.OpenWrite(LocalDestinationFilename))
- {
- sftp.DownloadFile(RemoteFileName, file);
- }
- sftp.Disconnect();
- }