class SFTP { private $resource = false; public function connect( $host, $port = 22 ) { $this->resource = ssh2_connect( $host, $port, [ 'hostkey'=>'ssh-rsa' ] ); } public function auth( $username, $privKey ) { if( $this->resource ) { ssh2_auth_pubkey_file( $this->resource, $username, $privKey . '.pub', $privKey ); } } public function sendFile( $file, $filename ) { if( $this->resource ) { ssh2_scp_send( $this->resource, $file, $filename, 0644 ); } } }