1

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.

1
  • Don't understand the -1, but whatever.. A simple it isn't supported would have sufficed. Jan 18 '18 at 0:20
4

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 ProFTPD/mod_sftp and Bitvise WinSSHD. It's not supported by the most widespread SFTP server, the OpenSSH.


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).

1

Unfortunately, the answer is no: the ftp/sftp protocol does not allow an offloaded remote copy.

2
1

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.

1
  • Some cloud providers only give you access via sftp and/or rsync and won't allow you to login via ssh. cdn77 does that. That's why such questions arise.
    – Gherman
    Feb 3 '20 at 9:07
1

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.

get file.txt
!mv file.txt copy_of_file.txt
put copy_of_file.txt
2
  • Thanks for the thought, but the problem was to reduce the overhead of moving files that are 30 GB+. I worked around the problem by a combination of ssh as well as sftp commands. Jan 18 '18 at 0:20
  • Well, it consumes significant amout of resourses both in terms of network traffic and io.
    – Gherman
    Feb 3 '20 at 9:04
0

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.

-1

sftp uses for source or destination the local file system. So, short answer, no.

1
  • Well for some reason sftp does enable you to remove and rename remote files for instance. But not copy them and not move between dirs. Unless you download and then upload.
    – Gherman
    Feb 3 '20 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.