简体   繁体   中英

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

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

在此处输入图像描述

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM