[英]Move multiple file from one directory to another on remote sftp server
I am connecting to my remote sftp using below command:我正在使用以下命令连接到我的远程 sftp:
sftp user@host
After inputing password next I get sftp prompt ie接下来输入密码后,我得到 sftp 提示,即
sftp>
My job is to move multiple files from directory A to directory B. I am able to do this via rename command but only single file at a time.我的工作是将多个文件从目录 A 移动到目录 B。我可以通过重命名命令执行此操作,但一次只能执行一个文件。 Is there any command/syntax which can move list of files from directory A to directory B. Something like below:是否有任何命令/语法可以将文件列表从目录 A 移动到目录 B。如下所示:
rename /A/file1 /A/file2 B/
Just to add I have to do it via command line only by using sftp protocol and Not any tool like fileZilla or winscp.只是补充一下,我必须通过命令行来完成,只能使用 sftp 协议,而不是像 fileZilla 或 winscp 这样的任何工具。
You've indicated in comments that you're trying to avoid anything which makes multiple requests to the SFTP server.您已在评论中指出您试图避免向 SFTP 服务器发出多个请求的任何内容。
The most widely implemented version of the SFTP protocol is Version 3, draft 02 . SFTP 协议实现最广泛的版本是版本 3,草案 02 。 Notably, this is the version implemented by OpenSSH which is the most widely used SFTP server software.值得注意的是,这是使用最广泛的 SFTP 服务器软件 OpenSSH 实现的版本。 That version of the protocol makes no mention of wildcards, and the command to rename a file renames a single file or directory from an old name to a new name.该版本的协议没有提及通配符, 重命名文件的命令会将单个文件或目录从旧名称重命名为新名称。
Any client that renames multiple files will have to issue one rename operation per file, possibly preceded by one or more operations to fetch the file names to be renamed.任何重命名多个文件的客户端都必须为每个文件发出一次重命名操作,可能在之前执行一项或多项操作以获取要重命名的文件名。 The client could provide the user with a single command to rename multiple files (or a drag-drop option, or whatever), but at the SFTP protocol level, it will necessarily have to issue at least one SFTP request per file.客户端可以向用户提供重命名多个文件的单个命令(或拖放选项,或其他),但在 SFTP 协议级别,它必须至少为每个文件发出一个 SFTP 请求。
Does it have to be sftp?必须是sftp吗?
You can issue commands as a block script with ssh directly.您可以直接使用 ssh 将命令作为块脚本发出。
ssh user@host '
echo "Moving files"
date
rename /A/file1 /A/file2 B/
date
' > logfile 2>&1
psftp
tool (from putty-tools) can move multiple files to another directory on remote server. psftp
工具(来自 putty-tools)可以将多个文件移动到远程服务器上的另一个目录。 Here is how I use it,这是我如何使用它,
mget *.ACT
ren *.ACT backup
If the second parameter of the ren
command is a directory then the first parameter can be a list of files or a wildcard, and it moves all files to the given directory.如果ren
命令的第二个参数是目录,则第一个参数可以是文件列表或通配符,它将所有文件移动到给定目录。
mv
command is also same as ren
. mv
命令也与ren
相同。
There is no mv
command using sftp.没有使用 sftp 的mv
命令。 The only solution is, like you've said, to use rename
.正如您所说,唯一的解决方案是使用rename
。
As a workaround in terminal, you can use ftputil in python.作为终端中的解决方法,您可以在 python 中使用ftputil 。 It has a rename function:它有一个重命名功能:
rename(source, target)
It renames the source file (or directory) on the FTP server.它重命名 FTP 服务器上的源文件(或目录)。
That way, you can easily connect to server, list directory, and create a loop to rename the listed files.这样,您可以轻松连接到服务器、列出目录并创建循环以重命名列出的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.