Is there a way, using sftp, to copy a file on a remote file system to the same file system?
What this means is
user@hostname:/path/file.txt
to user@hostname:/path/copy_of_file.txt
from a remote machine? I am doing remote testing and need to copy some large files on the remote system with out mirroring the file to or from the test system.
Most SFTP servers do not support duplication of a remote file.
There's
copy-file
extension to SFTP protocol. But it's supported by few SFTP servers only. For example by ProFTPDmod_sftp
and Bitvise WinSSHD. The most widespread SFTP server, the OpenSSH supports relatedcopy-data
only in very recent version 9.0.Quite often, when you have an SFTP access, you also have an SSH shell access. Then you can copy the files using shell commands (like
cp
in *nix).Unfortunately, the answer is no: the ftp/sftp protocol does not allow an offloaded remote copy.
Not really "using sftp", but since sftp uses SSH, can't you just log on the remote server using ssh, and copy your file normally ?
Another alternative I would consider would be using sshfs, which lets you mount your ssh dir as a virtual drive, and use commands like cp on it. I'm not sure about the performance, but it can be worth trying. This works even if your shell is disabled with something like
/bin/false
, which can be pretty handy.As indicated by previous answers, the protocol does not support what you need. You can work around this by downloading the file, renaming the downloaded copy on your own machine, and then upload it again. This is bulky, but if done as a part of an sftp script it does not really matter.
So I just had a similar problem and found your answer online. Even tough the thread is quite old I still want to share my answer.
I also did not find a solution to solve that problem with boardtools but there is some third-party software which does the trick quite well from sysax.com. They have a automation software to create a script, which can handle SFTP and other protocols.
sftp uses for source or destination the local file system. So, short answer, no.