I
I
Ivan Vekov2017-05-02 16:59:36
linux
Ivan Vekov, 2017-05-02 16:59:36

How to write SFTP get request in one line?

There was such task:
It is necessary to receive a remote file from a remote server, through SFTP, in one line.
To do this, there is an SFTP user, with a password (without it, too, in any way).
You also need to do it using a PHP file, let's say the exec () command - which executes commands as in the command line.
Tried all sorts of stupid options, like:

exec('sftp user:[email protected] get /home/www/x1/test/file.php /home/www/x2/test/file.php');

And
exec('sftp user:[email protected]:/home/www/x1/test/file.php /home/www/x2/test/file.php');

And
exec('sftp [email protected] && password && get /home/www/x1/test/file.php /home/www/x2/test/file.php');

But apparently I'm doing it all wrong.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Q
qlkvg, 2017-05-02
@vekov

If possible, install sshpass

sshpass -p <password> sftp <remote-username>@<remote-host>:/path/to/source /path/to/dest

D
dummyman, 2017-05-02
@dummyman

If there is ssh access, there is a simple command:
But first you need to make passwordless authorization using an ssh key
https://www.digitalocean.com/community/tutorials/h...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question