views:

80

answers:

6

Hi all,

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.

+2  A: 

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.

ZombieSheep
I use C, ssh code based on openssh.
datasunny
+1  A: 

Try looking at SFTP.

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

bta
A: 
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.

Dom
I have to programmingly transfer the file, because there are some memory/hard-disk restraints.
datasunny
A: 

Rsync can be of help:

rsync [email protected]:filename remotefilename
Tomislav Nakic-Alfirevic
A: 

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.

pgod