C# - 使用ftp通过SSH将文件从一台远程服务器下载到另一台 [英] C# - Download file using ftp over ssh from one remote server to another
问题描述
我有要求将大文件(20GB +)从一台远程服务器下载到另一台C#中的远程服务器。我们已经为其他文件操作建立了ssh连接。我们需要以二进制模式从ssh会话启动ftp下载(这是远程服务器要求以特定格式传送文件)。问题 - 如何在ssh会话中发送ftp命令来建立与证书的连接并将模式设置为'bin'?基本上等同于使用ssh:
pre $ F $ p $ FtpWebRequest request =(FtpWebRequest)WebRequest.Create
ftp:/ /xxx.xxx.xxx.xxx/someDirectory/someFile);
request.Credentials = new NetworkCredential(username,password);
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse response =(FtpWebResponse)request.GetResponse();
SSH是一个Secure SHell cmd提示符,因为你给它的命令来运行。它不是FTP。 SSH可以执行FTP实用程序或应用程序。
SSH确实有一些名为SFTP(或SSH文件传输协议)的东西,但没有内置.NET的东西(即BCL)要做到这一点。 FtpWebRequest
不支持SFTP。
尽管共享FTP,它们是不同的协议,并且与每个协议都不兼容其他。
如果您想启动FTP下载,您必须告诉SSH执行某种实用程序。如果您想启动SFTP传输,则可以发出sftp命令。但是,另一端需要支持sftp。或者,您可以发出scp命令(安全副本);但又一次,另一端将需要支持该协议(它不同于SFTP和FTP)...
如果你想写另一端,你会必须找到SFTP或SCP的第三方库......
I have requirement to download large files (20GB+) from one remote server to another remote server in C#. We already make ssh connections for other file operations. We need to initiate ftp download from ssh session in binary mode (this is remote server requirement to deliver file in specific format). Question - How do I send ftp command in ssh session to make connection with credentials and set mode as 'bin'? Basically equivalent of following using ssh:
FtpWebRequest request =(FtpWebRequest)WebRequest.Create(
@"ftp://xxx.xxx.xxx.xxx/someDirectory/someFile");
request.Credentials = new NetworkCredential("username", "password");
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
SSH is a "Secure SHell" This is like a cmd prompt in that you give it commands to run. It is not FTP. SSH could execute an FTP utility or application.
SSH does have something called SFTP (or SSH File Transfer Protcol) but there is nothing built into .NET (i.e. the BCL) to do that. FtpWebRequest
does not support SFTP.
Despite sharing "FTP" they're different protocols and are not compatible with each other.
If you want to initiate an FTP download, you'll have to tell SSH to execute a utility of some sort. If you want to initiate an SFTP transfer you can issue the sftp command. But, the other end will need to support sftp. Alternatively you an issue the scp command (secure copy); but again, the other end will need to support that protocol (it's different from SFTP and FTP)...
If you want to write the other end, you'll have to find a third-party library that does SFTP or SCP...
这篇关于C# - 使用ftp通过SSH将文件从一台远程服务器下载到另一台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!