Search code examples
linuxrecursionuploadconsolesftp

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.


Solution

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