Using sftp like scp

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 [email protected]

or

echo put /local/path.txt /remote/path/file.txt | sftp [email protected]

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 [email protected]:/remote/path/file.txt /local/path.txt

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

Use of sftp:// prefix is also possible since OpenSSH 7.7, which somewhat modifies the syntax (allows URL encoding of the username and the path).


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

There's similar question on Stack Overflow: Single line sftp from terminal