开发者

Transfer file over 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 file开发者_Go百科s 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.


echo "hello" | ssh user@SSHHost "cat - > /tmp/file"

I juste read the file, pipe it in SSH, and write on the SSHHost server in the /tmp/file.


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.


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.

ssh test@example.org "cd mydir && tar cfp - mysubdir" | tar xvfp -

Be careful about sparse files, etc, when you do this. Most tars have an option to preserve file holes during this sort of process.


Try looking at SFTP.

Edit: You might also find this article useful regarding running rsunc over ssh.


Rsync can be of help:

rsync usernamea@server.com:filename remotefilename


To download: remote -> local
scp user@remote_host:remote_file local_file 

To upload: local -> remote
scp local_file user@remote_host:remote_file

For multiple files, include -r after scp.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜