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:

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


2 Answers 2


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

  • 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 Commented Feb 11, 2013 at 12:21
  • @RandomWhiteTrash I added a solution so you can run it from cron.
    – pkhamre
    Commented Feb 11, 2013 at 12:41

I wanted to sync a whole dir (with all the subfolders also recursively). I could not get it done with sftp but I was able to do it with yafc

Install it (OSX)

brew install yafc

Connect to the server

yafc sftp://[email protected]

Assuming "example" folder exists locally, -r for recursive, -f for forcing (no asking to overwrite)

put -rf example

In my case I need to also chmod the files because the permissions were not copied (not even with -p flag)

chmod 0755 example/*

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .