可能以前已经有人问过了,我是PHP新手,正在尽力学习,但这真的让我困惑。
基本上我想知道的是,如何使用PHP代码将所有内容从远程服务器下载到本地位置。 我卡在了下载所有内容而不仅仅是一个文件上。所以请问有人能向我展示/解释如何做到这一点吗?
目前我所拥有的:
<?php
$connection - ssh2_connect('example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$remote_dir="/remote_dir/";
$local_dir="/local_dir/";
$remote ="$remote_dir";
$stream = ssh2_exec($connection, $remote);
stream_set_blocking($stream,true);
$command=fread($stream,4096);
$array=explode(\n,$command);
$total_files=sizeof($array);
for($i=0;$i<$total_files;$i+++){
$file_name=trim($array[$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);
?>
我认为我的 $remote ="$remote_dir"; 是有问题的,说实话当我想要整个目录时,我得到了 $filename。这是我目前拥有的全部内容。