note 97997 modified in function.ssh2-scp-recv by danbrown

From: Date: Wed, 19 May 2010 22:20:50 +0000
Subject: note 97997 modified in function.ssh2-scp-recv by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169433@lists.php.net to get a copy of this message
This function can be used to copy all files into a directory on a remote server, using SSH and SCP. <?php $connection = ssh2_connect('host', 22); ssh2_auth_password($connection, 'user', 'password'); $remote_dir="/remote_dir/"; $local_dir="/local_dir/"; $com ="ls $remote_dir"; $stream = ssh2_exec($connection, $com); stream_set_blocking($stream,true); $cmd=fread($stream,4096); $arr=explode("\n",$cmd); $total_files=sizeof($arr); for($i=0;$i<$total_files;$i++){ $file_name=trim($arr[$i]); if($file_name!=''){ $remote_file=$remote_dir.$file_name; $local_file=$local_dir.$file_name; if(ssh2_scp_recv($connection, $remote_file,$local_file)){ echo "File ".$file_name." was copied to $local_dir<br />"; } } } fclose($stream); ?> --was-- This function can be used to copy all files into a directory on a remote server, using SSH and SCP. $connection = ssh2_connect('host', 22); ssh2_auth_password($connection, 'user', 'password'); $remote_dir="/remote_dir/"; $local_dir="/local_dir/"; $com ="ls $remote_dir"; $stream = ssh2_exec($connection, $com); stream_set_blocking($stream,true); $cmd=fread($stream,4096); $arr=explode("\n",$cmd); $total_files=sizeof($arr); for($i=0;$i<$total_files;$i++){ $file_name=trim($arr[$i]); if($file_name!=''){ $remote_file=$remote_dir.$file_name; $local_file=$local_dir.$file_name; if(ssh2_scp_recv($connection, $remote_file,$local_file)){ echo "File ".$file_name." was copied to $local_dir<br />"; } } } fclose($stream); http://php.net/manual/en/function.ssh2-scp-recv.php

« previous php.notes (#169433) next »