这可能是之前被问到的,我是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);
?>
Run Code Online (Sandbox Code Playgroud)
我想我的$ remote ="$ remote_dir"; 是错的,说实话,当我需要整个目录时,我有$ filename,这是我到目前为止所有的.