Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Just like the title sugests I have a local dir, say:

/home/whoever/files_to_send

And I want to send all files in that dir to a remote location:

my_user@my.server.com:/some/remote/directory

How do I do that with SFTP?

PS. I need an answer for SFTP specificaly, I can not use SCP or anything else.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You can use the put command with the -r option for a recursive copy.

 put [-Ppr] local-path [remote-path]
         Upload local-path and store it on the remote machine.  If the remote path name is not specified, it is given the same name it has on the local machine.  local-path may contain glob(3) char‐
         acters and may match multiple files.  If it does and remote-path is specified, then remote-path must specify a directory.

         If either the -P or -p flag is specified, then full file permissions and access times are copied too.

         If the -r flag is specified then directories will be copied recursively.  Note that sftp does not follow symbolic links when performing recursive transfers.

Interactive mode

$ sftp my.server.com 
Connected to my.server.com.
sftp> put -r /home/whoever/files_to_send /some/remote/directory

Single command for cron runs

$ cat batchfile
put -r /home/whoever/files_to_send /some/remote/directory
$ sftp -b batchfile my.server.com

What you should really learn from this is to read the online manual, sftp(1).

share|improve this answer
    
Thanks for your answer, however I, preferably, need to execute it in one line command or some other clever way so I can run it via cron –  RandomWhiteTrash Feb 11 '13 at 12:21
    
@RandomWhiteTrash I added a solution so you can run it from cron. –  pkhamre Feb 11 '13 at 12:41
    
That's great thanks! –  RandomWhiteTrash Feb 11 '13 at 14:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.