Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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

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
up vote 6 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 
Connected to
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

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


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.