doswy02440 2019-02-14 09:46
浏览 507
已采纳

如何从ftp服务器获取文件并在自己的服务器上复制

I want to get file from client server and copy them on my server , I have successfully connected to client server, my code is below.

// connect and login to FTP server
$ftp_server = "xx.xxx.xxx.xxx";
$ftp_username = 'xxxxxxxxxxxxxxx';
$ftp_userpass = 'xxxxxxxxxxxxxxxx';
 $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
echo "<pre>";
 print_r($login);
  echo "</pre>";
 // get the file list for /
 $filelist = ftp_rawlist($ftp_conn, "/");

// close connection
ftp_close($ftp_conn);
echo "<pre>";
print_r($filelist);
echo "</pre>";
// output $filelist
var_dump($filelist);

May anyone please advise how can I achieve this?

  • 写回答

2条回答 默认 最新

  • duanliaoyin3171 2019-02-16 06:56
    关注

    This is how I resolved this now all files will copy on your server. use ftp_ssl_connect if its secure

    $ftp_server = "xx.xxx.xxx.xxx";
    $ftp_username = 'xxxxxxxxxxxxxx';
    $ftp_userpass = 'xxxxxxxxxxxxxxxxxxx';
    
    $ftp_conn = ftp_ssl_connect($ftp_server) or die("Could not connect to $ftp_server");
    $login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
    
    ftp_pasv($ftp_conn,pasv);
    
    
    $output_directory="files1/ftpgetfiles/137/";
    // get the file list for /
    $filelist = ftp_nlist($ftp_conn, "/");
    
    foreach ($filelist as $key => $value) {
    $fp = fopen($output_directory.$value,"w");
    if(ftp_fget($ftp_conn, $fp, $value, FTP_BINARY))
    {
        fclose($fp);
    }
    }
    
    ftp_close($ftp_conn);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥100 单片机hardfaulr
  • ¥20 手机截图相片分辨率降低一半
  • ¥50 求一段sql语句,遇到小难题了,可以50米解决
  • ¥15 速求,对多种商品的购买力优化问题(用遗传算法、枚举法、粒子群算法、模拟退火算法等方法求解)
  • ¥100 速求!商品购买力最优化问题(用遗传算法求解,给出python代码)
  • ¥15 虚拟机检测,可以是封装好的DLL,可付费