PHPでSCPを利用する場合、「libssh2」パッケージ、またはPECLの「ssh2」をインストールする必要がある。
aptitude install libssh2-php
ssh2_connectをリソースとして、ログイン名、パスワードは平文で利用できる。
function scpUploadFile($file_path, $remote_path) { $connect = ssh2_connect($this->host, $this->scp_port); $is_auth = ssh2_auth_password($connect, $this->login_name, $this->password); if (file_exists($file_path)) { $is_success = ssh2_scp_send($connect, $file_path, $remote_path); } } function scpDownloadFile($file_path, $remote_path) { $connect = ssh2_connect($this->host, $this->scp_port); $is_auth = ssh2_auth_password($connect, $this->login_name, $this->password); $is_success = ssh2_scp_recv($connect, $remote_path, $file_path); }