PHP
Chilkat2 PHP
SCP Upload File
See more SCP Examples
Demonstrates how to upload a file using the SCP protocol (Secure Copy Protocol over SSH).Chilkat PHP Downloads
<?php
use Chilkat2\Scp;
use Chilkat2\Ssh;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$ssh = new Ssh();
// Connect to an SSH server:
// Hostname may be an IP address or hostname:
$hostname = 'www.some-ssh-server.com';
$port = 22;
try {
$ssh->Connect($hostname, $port);
// Wait a max of 5 seconds when reading responses..
$ssh->IdleTimeoutMs = 5000;
// Authenticate using login/password:
$ssh->AuthenticatePw('myLogin', 'myPassword');
// Once the SSH object is connected and authenticated, we use it
// as the underlying transport in our SCP object.
$scp = new Scp();
$scp->UseSsh($ssh);
$remotePath = 'test.txt';
$localPath = '/home/bob/test.txt';
$scp->UploadFile($localPath, $remotePath);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
echo "SCP upload file success.\n";
// Disconnect
$ssh->Disconnect();