If you just want to transmit a file and don't care about using scp
or sftp
, then I would encourage you to use scp
. Here comes a basic example (taken from the PHP manual):
$connection = ssh2_connect('www.example.com', 22);
if($connection === FALSE) {
die('Failed to connect');
}
$state = ssh2_auth_password($connection, 'username', 'password');
if($state === FALSE) {
die('Failed to authenticate');
}
$state = ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);
if($state === FALSE) {
die('Failed to transfer the file');
}