using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using WinSCP; using System.IO; namespace WinScpTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { // Setup session options SessionOptions sessionOptions = new SessionOptions { GiveUpSecurityAndAcceptAnySshHostKey = true, Protocol = Protocol.Sftp, HostName = "sftp.marexspectron.com", UserName = "spectrometerEuropeS", Password = "Yy7sJc", //SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" }; using (Session session = new Session()) { // Connect session.Open(sessionOptions); string remotePath = "/"; if (session.FileExists(remotePath)) { RemoteDirectoryInfo directory = session.ListDirectory(remotePath); foreach (RemoteFileInfo fileInfo in directory.Files) { string remoteFilePath = "/" + fileInfo.Name; string localPath = @"D:\BackUp\" + fileInfo.Name; session.GetFiles(remoteFilePath, localPath).Check(); } } } } catch (Exception ex) { Console.WriteLine("Error: {0}", ex); } } } }