Chris
Chris

Reputation: 661

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.

Upvotes: 55

Views: 117648

Answers (5)

Ben Thielker
Ben Thielker

Reputation: 4164

The answer is:

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

Upvotes: 231

Byron
Byron

Reputation: 9

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

Upvotes: 0

Eugene S
Eugene S

Reputation: 6910

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.

Upvotes: 32

Girdhar Singh Rathore
Girdhar Singh Rathore

Reputation: 5585

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

enter image description here

Upvotes: 5

IneQuation
IneQuation

Reputation: 1264

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

Upvotes: -11

Related Questions