简体   繁体   中英

Connect to FTP site using SFTP and download files

I need to download all the files from a FTP site. But i need to connect SFTP to connect. I am unable to find examples/tutorials to download files from the FTP site using SFTP to connect.

Can someone please point me to a tutorial or provide some sample code to begin with ?

Tamir's SharpSSH library handles SFTP pretty well. And there are plenty of examples, but the gist is:

Sftp sftp = new Sftp(sftpHost, sftpUser);
Console.WriteLine("success");

// assuming public/private key authentication here...
sftp.AddIdentityFile(privateKeyFileName, privateKeyFilePassPhrase);
sftp.Connect(sftpPort);
ArrayList files = sftp.GetFileList(".");                
foreach (string file in files)
{
Console.WriteLine("\t{0}", file);
}

sftp.Close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM