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

查看:167
本文介绍了在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天全站免登陆