简体   繁体   English

使用SFTP连接到FTP站点并下载文件

[英]Connect to FTP site using SFTP and download files

I need to download all the files from a FTP site. 我需要从FTP站点下载所有文件。 But i need to connect SFTP to connect. 但是我需要连接SFTP进行连接。 I am unable to find examples/tutorials to download files from the FTP site using SFTP to connect. 我找不到使用SFTP连接从FTP站点下载文件的示例/教程。

Can someone please point me to a tutorial or provide some sample code to begin with ? 有人可以给我指出一个教程或提供一些示例代码开始吗?

Tamir's SharpSSH library handles SFTP pretty well. Tamir的SharpSSH库可以很好地处理SFTP。 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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