通过 ssh 传输文件
ssh协议中,有文件传输的机制吗?
我正在开发一个现有的代码库,其中已经有 ssh 设施代码。现在我需要通过 ssh 连接传输文件。如果 ssh 协议已经支持它,我就不必将 scp 内容集成到其中。
谢谢。
编辑:
我使用C,基于openssh的ssh代码。
由于某些限制,我必须以编程方式传输文件,而不是使用外部程序/命令。该程序应该在远程主机上逐块传输任何大小的文件,并即时处理该块。然后块数据被丢弃。
In ssh protocol, is there a mechanism for file transfer?
Im working on a existing code base which already has ssh facilities code. Now i need to transfer files over ssh connection. If ssh protocol already support it, i don't have to integrate scp stuff into it.
Thanks.
Edit:
Im using C, ssh code based on openssh.
I have to transfer the file programmingly, not using a external program/command because of some constraints. The program supposed to transfer any size file on remote host chunk-by-chunk, and process the chunk on-the-fly. Then the chunk data is discarded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我只是读取该文件,将其通过 SSH 传输,然后在 SSHHost 服务器上的 /tmp/file 中写入。
I juste read the file, pipe it in SSH, and write on the SSHHost server in the /tmp/file.
sftp 和 scp 都是现有的“安全”文件传输方法,但您的答案将取决于您的应用程序使用的技术堆栈。您没有提及是否使用 C#、PHP 或其他语言,也没有提及您的应用程序在哪种机器上运行。这些事情将对您得到的答案产生重大影响。
sftp and scp are both existing "secure" file transfer methods, but your answers are going to depend on what technology stack you are using for your application. You don't mention whether you're using C#, PHP or another language, or what kind of machine your app runs on. These things will have a big bearing on the answers you will get.
老式的方法是“tar-to-tar”,它可以很好地复制和保留权限。当双方都有 rsync 时,这在很大程度上已被 rsync 的使用所取代。
执行此操作时,请注意稀疏文件等。大多数 tars 都可以选择在此类过程中保留文件漏洞。
The old-school way is "tar-to-tar" which does a good job of copying and preserving permissions. This has largely be superseded by use of rsync when both sides have rsync.
Be careful about sparse files, etc, when you do this. Most tars have an option to preserve file holes during this sort of process.
尝试查看SFTP。
编辑:您可能还会发现这篇文章对于跑步很有用通过 ssh 进行 rsunc。
Try looking at SFTP.
Edit: You might also find this article useful regarding running rsunc over ssh.
Rsync 可以提供帮助:
Rsync can be of help:
对于多个文件,请在 scp 后包含
-r
。For multiple files, include
-r
after scp.