如何在 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
How can I upload an entire folder, that contains other folders, using sftp on linux?
提问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 -r
is -recursively copy entire directories.
这会将目录“foo”从本地主机复制到远程主机的目录“bar”。这-r
是 -recursively 复制整个目录。
You can also use rcp
with similar syntax. The only difference between them is that scp
uses secure shell and rcp
uses 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 put
specifically, please refer to Ben Thielker answer here.
更新:对于想要put
专门使用的用户,请参阅此处的 Ben Thielker 回答。
回答by IneQuation
Use scp
instead. 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
回答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