How can I upload an entire folder, that contains other folders, using sftp on linux?

I have tried put -r directory/*, which only uploaded the files and not folders. Gave me the error, cannot Couldn't canonicalise.

Any help would be greatly appreciated.


For people actually wanting a direct answer to this question (instead of being told to use something other than sftp)...

put -r local/path/to/directoryName

The uploaded directory must already exist in the working directory on the server, so you might need to create it first.

mkdir directoryName

Here you can find detailed explanation as how to copy a directory using scp. In your case, it would be something like:

$ scp -r foo [email protected]:/some/remote/directory/bar

This will copy the directory "foo" from the local host to a remote host's directory "bar". Here -r is -recursively copy entire directories.

You can also use rcp with similar syntax. The only difference between them is that scp uses secure shell and rcp uses remote shell.

BTW The "Couldn't canonicalise" error you mentioned appear when sftp server is unable to access the file/directory mentioned in the command.

UPDATE: For users who want to use put specifically, please refer to Ben Thielker answer here.


sftp> mkdir source
sftp> put -r source
 Uploading source/ to /home/myself/source
 Entering source/
 source/file1
 source/file2

enter image description here