PHP SFTP/SSH transfer?

As Antonio suggests you could simply exec scp - but this is only going to work if you've got key pairs set up A more flexible solution (assuming ssh is a requirement) would be to use the ssh bindings in PHP.

As is too often the case here, you've not provided much information about what you are trying to achieve nor the constraints. Where does the image originate from? How quickly does it need to be replicated?

Are the servers equivalent nodes in a cluster? Since both servers are already talking HTTP, why use a different protocol for transferring content? As Antonio suggests you could simply exec scp - but this is only going to work if you've got key pairs set up.

A more flexible solution (assuming ssh is a requirement) would be to use the ssh bindings in PHP.

I've had a look at this but I'm struggling to understand what to do. So far I have downloaded the phpseclib files and put them in the same directory as my PHP script, and then I have added include('/Net/SSH2. Php'); to the script file.

I've also downloaded openssl but I don't know what to do with that, could you explain please? Thanks – Daniel H Jun 22 at 13:03 I did phpinfo() and it says that openssl is already enabled. The error I'm getting is 'Call to undefined function ssh2_connect()', does that mean I've installed the phpseclib files wrongly?

– Daniel H Jun 22 at 13:10 It means you've not got the ssh2 PECL installed. How you about gettnig it depends on which version of PHP you are using, what OS you are running on, and where you got the PHP from. – symcbean Jun 22 at 15:51.

A simple way to handle this is to call PHP exec and execute a unix scp call. Exec("scp $local_file user1@somehost:$remote_file").

I have updated my question with the code I have but it is not transferring the image to the 2nd server. Am I doing something wrong? – Daniel H Jun 22 at 12:38 1 Symcbean is correct, I forgot to mention that you need to have your key pairs set to authenticate the scp.

Setting that up does make my answer a bit more complicated. Look at symcbean's solution, that might be a better way to go about it. – Antonio Haley Jun 22 at 12:49.

You can try ssh2_scp_send: $connection = ssh2_connect('shell.example. Com', 22); ssh2_auth_password($connection, 'username', 'password'); ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions