1

I have backup space that is accessible by SFTP. I have made a backup in a directory called "mybackup" on this remote storage. I would now like to make a copy of the mybackup directory called "mybackup-copy" also on the remote storage.

Is there a way to do this with SFTP that doesn't involve downloading the whole directory and then re-uploading the whole directory?

As in, if I had full SSH shell access I could do cp -ar mybackup mybackup-copy - can this be achieved with the sftp protocol?

artfulrobot
  • 2,929
  • Can you use scp? When using scp remote_location1 remote_location2, scp copies directly between location1 and location2, unless you use -3 parameter. -3 transfers files from remote 1 to the machine performing the scp command, and then to remote2. I suspect scp without -3 might be able to do it. https://man7.org/linux/man-pages/man1/scp.1.html – nobody Nov 09 '20 at 12:26
  • @nobody I got hopeful on that, but no, seems that's not supported by the host. Good tip though, thanks! – artfulrobot Nov 09 '20 at 16:18

2 Answers2

2

A core SFTP protocol does not support copying remote files. There's draft of copy-data/copy-file extension to the SFTP protocol.

But in the most widespread OpenSSH SFTP server the copy-data is supported by very recent version 9.0 only. Its sftp client has cp command (but you also need a compatible server).

Another servers that do support the extensions are ProFTPD mod_sftp and Bitvise SFTP server.


So using the shell cp command is typically the only way.

0

If the remote end supports scp this should work:

scp -p host:/path/to/file/filename.ext host:/path/to/copy/of/file/

Or, since you say you're seeking to copy a directory:

scp -rp host:/path/to/directory host:/path/to/copy/

Assuming that directory /path/to/copy exists on host, the latter command will result in a new directory /path/to/copy/directory on host.

Jim L.
  • 7,997
  • 1
  • 13
  • 27
  • Thanks but was asking about SFTP because SCP not available - see above. – artfulrobot May 28 '21 at 08:45
  • @artfulrobot It never hurts to check, since the underlying protocol is similar. I know I personally have deployed sites that support sftp, scp and rsync, since they're all based on the SSH protocol. – Jim L. May 28 '21 at 16:59