这可能之前已经问过,我是PHP新手,并且尽力学习尽可能多,但这实际上已经抛出了我。通过sftp从远程服务器下载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_dir”;是错误的,说实话我有$文件名,当我想要整个目录,这是迄今为止我所有。
发布您到目前为止所做的事情,并且不要忘记更换任何敏感信息(如果有)。 – Prix
刚刚添加了迄今为止我所拥有的。就像我说的我不知道它是对的还是不是只在几周前开始使用PHP,但我可能在我的头上。 – user2589167
已发布样本希望你喜欢,因为你是新来的Stackoverflow [**我也建议你去旅行到Stackoverflow之旅,以了解如何最好地使用这个网站,这将帮助你很大程度上未来的问题。** ](http://stackoverflow.com/about) – Prix