Using sftp like scp

4

1

As OpenSSH guys said "The scp protocol is outdated", it's time to think about post-scp days.

However sftp seems to be designed to interactive operation. Is there good way to use sftp command like scp? means, how to do this on sftp?

scp ./myfile myserver:/home/myfile

Or, any good scp successor?

mogya

Posted 2019-05-08T02:07:21.080

Reputation: 43

2Note: sftp myserver:/home/myfile ./myfile seems to work (at least on Debian and its derivatives) but not the other way around. – Kamil Maciorowski – 2019-05-08T04:49:36.837

Answers

2

sftp command is indeed built around commands (like ftp). So it cannot work as an in-place replacement for scp.

Though you can use one-liners like:

echo get /remote/path/file.txt /local/path.txt | sftp user@example.com

or

echo put /local/path.txt /remote/path/file.txt | sftp user@example.com

You may want to add -b - to force a non-interactive mode.


Interestingly (as @Kamil mentioned), for downloads, you can also use this scp-like syntax:

sftp user@example.com:/remote/path/file.txt /local/path.txt

(the use of the second argument is not documented).


There's also free/open-source pscp command-line client that comes in PuTTY package, which is available for Linux (while more commonly used on Windows). It has an identical command-line interface to OpenSSH scp. But contrary to its name and scp, it's primarily SFTP client (while it can fallback to SCP, if the server does not support SFTP).

Despite its name, PSCP (like many other ostensible scp clients) can use either of these protocols.

...

Normally PSCP will attempt to use the SFTP protocol, and only fall back to the SCP protocol if SFTP is not available on the server.

You can install PuTTY/pscp with apt-get like:

sudo apt-get install -y putty

Martin Prikryl

Posted 2019-05-08T02:07:21.080

Reputation: 13 764

3Probably it's possible to write a wrapper that uses sftp but its syntax is scp-like. – Kamil Maciorowski – 2019-05-08T05:02:06.630

wikipedia mentions an scp2command which is scp-over-sftp, and given the similarities in the man pages between my scp and my sftp I wonder if the scpin my Ubuntu isn't already scp2. – xenoid – 2019-05-08T07:23:28.330

1@xenoid I believe that scp2 comes with some commercial SSH implementations like Tectia and ssh.com only. There's no scp2 in OpenSSH, what is de-facto standard SSH implementation in all Linux distributions. -- Btw, PuTTY pscp also works like ssh2. It is actually an SFTP client with scp-like command-line interface. Though, it can fall back to SCP, if the server does not support SFTP. – Martin Prikryl – 2019-05-08T12:45:20.323

As there's actually Linux distribution of PuTTY/pscp, I've added this to my answer. – Martin Prikryl – 2019-05-08T13:18:33.563

0

You should also consider rsync. Except for the remote1-to-remote2 transfer that scp allows, it appears -- from a quick read of man scp anyway -- that you could make rsync do all of that quite easily, or write a wrapper that is not too painless.

Rsync has other advantages that you get by default (viz., much more efficient when replacing an older file), even if you don't use any of it's many options.

sitaram

Posted 2019-05-08T02:07:21.080

Reputation: 296