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