如何在 linux 上使用 sftp 上传包含其他文件夹的整个文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10084941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:42:04  来源:igfitidea点击:

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

linuxrecursionuploadconsolesftp

提问by Chris

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

我试过put -r directory/*,它只上传文件而不是文件夹。给我错误,不能Couldn't canonicalise

Any help would be greatly appreciated.

任何帮助将不胜感激。

采纳答案by Eugene S

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

在这里您可以找到有关如何使用scp. 在你的情况下,它会是这样的:

$ 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 -ris -recursively copy entire directories.

这会将目录“foo”从本地主机复制到远程主机的目录“bar”。这-r是 -recursively 复制整个目录。

You can also use rcpwith similar syntax. The only difference between them is that scpuses secure shell and rcpuses remote shell.

您也可以使用rcp类似的语法。它们之间的唯一区别是scp使用安全外壳和rcp使用远程外壳。

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

顺便说一句,当 sftp 服务器无法访问命令中提到的文件/目录时,会出现您提到的“无法规范化”错误。

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

更新:对于想要put专门使用的用户,请参阅此处的 Ben Thielker 回答。

回答by IneQuation

Use scpinstead. It uses SSH too and can easily handle recursion.

使用scp来代替。它也使用 SSH,可以轻松处理递归。

回答by Ben Thielker

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

对于实际上想要直接回答这个问题的人(而不是被告知使用 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

回答by Girdhar Singh Rathore

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

enter image description here

在此处输入图片说明

回答by Byron

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

如果您在使用 sftp 时遇到问题,可以使用 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