Skip to content

Instantly share code, notes, and snippets.

@wilk
Created July 2, 2013 15:57
Show Gist options
  • Save wilk/5910565 to your computer and use it in GitHub Desktop.
Save wilk/5910565 to your computer and use it in GitHub Desktop.
Use SSH2 with PHP 5.3.x
// 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