假设我在远程 SFTP 服务器上有一个文件 /home/user/dir1/file.txt
。我想将此文件复制到 /home/user/dir2/file.txt
,而我在 sftp
session 中(我的服务器只允许 sftp
连接,但没有 ssh
连接!)连接到此服务器?
有可能吗?如果是,命令是什么?
例如,以下命令会将文件从远程服务器上的一个目录移动到另一个目录。
sftp> rename dir1/file.txt dir2/file.txt
我正在寻找一个命令,该命令可以将文件从一个目录复制到远程服务器上的另一个目录(如果存在的话)。
解决方法是从第一个位置下载文件并上传到第二个位置,但是当相关文件很大并且网络连接速度较慢时,这不是一个选项!
最佳答案
不确定“命令”是什么意思。您指的是 SFTP 协议(protocol)请求吗?或者一些可脚本化/命令行 SFTP 客户端的命令(例如 OpenSSH sftp
)?
SFTP 协议(protocol)本身不允许复制远程文件。虽然有一个名为 copy-file
的协议(protocol)的可选扩展可以满足此目的。
引用copy-file
extension specification :
6. Copying Remote Files
byte SSH_FXP_EXTENDED uint32 request-id string "copy-file" string source-file string destination-file bool overwrite-destination
This request copies a file from one location to another on the server. The server responds with SSH_FXP_STATUS.
虽然没有多少 SFTP 服务器支持扩展。我知道ProFTPD mod_sftp
和 Bitvise WinSSHD 可以。 OpenSSH 仅在最近的 version 9.0 中支持相关的 copy-data
.
关于copy - 在 SFTP session 中,是否可以将一个远程文件复制到同一远程 SFTP 服务器上的另一个位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26260056/