简体   繁体   English

将多个文件从一个目录移动到远程 sftp 服务器上的另一个目录

[英]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.

相关问题 用于在远程SFTP服务器上移动文件的Shell脚本 - Shell script to move files on remote SFTP Server 通过 sftp 从 Hadoop 发送文件到远程服务器 - Send a file from Hadoop to a remote server via sftp 使用 Paramiko 将文件从一个目录移动到另一个目录 - Move files from one directory to another with Paramiko 将SFTP私钥从一台服务器复制到另一台服务器 - Copy SFTP private key from one server to another 将文件移动到另一个目录中的目录并在一个命令行中重命名它? - Move a file to a directory that is within another directory and rename it in one command line? 从远程服务器到本地服务器的Sftp文件 - Sftp files from Remote server to local server 在Linux中,如何在一行中编辑文件并将文件从一个目录移动到另一目录? - How to edit and move a file from one directory to another in one line in Linux? Linux:如何在不登录的情况下将文件从一个文件夹移动到远程计算机中的另一个文件夹 - Linux : How to move a file from one folder to another folder in a remote machine without logging in 在Ubuntu上,有没有办法自动将文件移动到另一个目录,因为它们是SFTP的? - On Ubuntu, Is there a way to automatically move files to another directory as they are SFTP'd? 如何从 SFTP 服务器获取文件并将它们移动到 bash 脚本中的另一个文件夹? - How do I get the files from SFTP server and move them to another folder in bash script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM