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

LinuxRecursionUploadConsoleSftp

Linux Problem Overview


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.

Linux Solutions


Solution 1 - Linux

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

Solution 2 - Linux

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 your_username@remotehost.edu:/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.

Solution 3 - Linux

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

enter image description here

Solution 4 - Linux

if you have issues using sftp, you can use ncftp For centos

yum install ncftp

To copy a whole directory recursively

ncftpput -R -v -u username -P 21 ftp.server.dev /remote-path/ /localdirectory

Solution 5 - Linux

Use scp instead. It uses SSH too and can easily handle recursion.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChrisView Question on Stackoverflow
Solution 1 - LinuxBen ThielkerView Answer on Stackoverflow
Solution 2 - LinuxEugene SView Answer on Stackoverflow
Solution 3 - LinuxGirdhar Singh RathoreView Answer on Stackoverflow
Solution 4 - LinuxByronView Answer on Stackoverflow
Solution 5 - LinuxIneQuationView Answer on Stackoverflow