datasunny
datasunny

Reputation: 291

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 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.

Upvotes: 13

Views: 18934

Answers (6)

Gopinath
Gopinath

Reputation: 77

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.

Upvotes: 1

pgod
pgod

Reputation: 603

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 [email protected] "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.

Upvotes: 4

Tomislav Nakic-Alfirevic
Tomislav Nakic-Alfirevic

Reputation: 10173

Rsync can be of help:

rsync [email protected]:filename remotefilename

Upvotes: 1

Dom
Dom

Reputation: 353

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.

Upvotes: 22

bta
bta

Reputation: 45057

Try looking at SFTP.

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

Upvotes: 2

ZombieSheep
ZombieSheep

Reputation: 29953

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.

Upvotes: 5

Related Questions