Created
July 2, 2013 15:57
-
-
Save wilk/5910565 to your computer and use it in GitHub Desktop.
Use SSH2 with PHP 5.3.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open connection | |
If (!($hConnection = ssh2_connect (‘my.server.com’, 22))) throw new Exception (‘connection refused’); | |
// Authentication | |
if (ssh2_auth_password ($hConnection, ‘user’, ‘pass’)) { | |
// Here are your dirty things in secure shell =) | |
// Such as, initialize a sftp connection | |
$hSFTP = ssh2_sftp ($hConnection); | |
// and upload a file on it | |
file_put_contents ("ssh2.sftp://$hSFTP/file_to_upload.csv", file_get_contents (‘file_to_upload.csv’)); | |
} | |
else throw new Exception (‘wrong user or pass’); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment