在 SFTP 会话中,是否可以将一个远程文件复制到同一远程 SFTP 服务器上的另一个位置? [英] In an SFTP session is it possible to copy one remote file to another location on same remote SFTP server?

查看:33
本文介绍了在 SFTP 会话中,是否可以将一个远程文件复制到同一远程 SFTP 服务器上的另一个位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在远程 SFTP 服务器上有一个文件 /home/user/dir1/file.txt.我想复制这个文件,让我们说 /home/user/dir2/file.txt,而我在 sftp 会话中(我的服务器只允许 sftp 连接,但没有 ssh 连接!)连接到此服务器?

Let say I have a file /home/user/dir1/file.txt on a remote SFTP server. I want to copy this file to lets say /home/user/dir2/file.txt, while I am in a sftp session (I have server which allows only sftp connections, but no ssh connections!) connected to this server?

有可能吗?如果是,命令是什么?

Is it possible to do so? If yes, what is the command?

例如,以下命令将重命名将文件从远程服务器上的一个目录移动到另一个目录.

For example the following command would rename move a file from one directory to another on the remote server.

sftp> rename dir1/file.txt dir2/file.txt

我正在寻找一个命令,该命令将文件从一个目录复制到远程服务器上的另一个目录(如果存在).

I am looking for a command which would copy a file from one directory to another on the remote server, if one exists.

解决方法是从第一个位置下载文件并上传到第二个位置,但当相关文件很大且网络连接速度较慢时,这不是一个选项!

The work around is to download the file from first location and upload to the second location, but that is not an option when the file in question is a big one and one is working with a slow network connection!

推荐答案

不知道你说的命令"是什么意思.您指的是 SFTP 协议请求吗?还是一些可编写脚本/命令行 SFTP 客户端的命令(例如 OpenSSH sftp)?

Not sure what you mean by the "command". Are you referring to an SFTP protocol request? Or a command of some scriptable/command-line SFTP client (e.g. the OpenSSH sftp)?

SFTP 协议本身不允许复制远程文件.尽管有一个名为 copy-file 的协议的可选扩展可以达到目的.

The SFTP protocol on its own does not allow duplication of a remote file. Though there's an optional extension of the protocol named copy-file that serves the purpose.

引用 复制文件 扩展规范:

Quoting the copy-file extension specification:

6.复制远程文件

byte   SSH_FXP_EXTENDED
uint32 request-id
string "copy-file"
string source-file
string destination-file
bool   overwrite-destination

此请求将文件从服务器上的一个位置复制到另一个位置.服务器以 SSH_FXP_STATUS 响应.

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 没有(无论是服务器,也不是 sftp 客户端).

Not many SFTP servers support the extension though. I know that ProFTPD/mod_sftp and Bitvise WinSSHD do. Notably, the OpenSSH does not (neither the server, nor the sftp client).

这篇关于在 SFTP 会话中,是否可以将一个远程文件复制到同一远程 SFTP 服务器上的另一个位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆