donglinxia1541 2017-03-14 21:30 采纳率: 0%
浏览 150
已采纳

PHP脚本从另一台服务器获取文件并保存在我的服务器上

I have been playing around with a few php scripts trying to first at least get the php file to connect to the ftp on my distributors file and THEN i would like it to save on my file. I was going to save this as a cron to run this script daily. I can't get it to connect to the distributors ftp. Their ftp access is ftp.aphrodite.WEBSITE.net The exact location of the file is ftp.aphrodite.WEBSITE.net/exporting/xml/products.xml I can acces it with filezilla and my browser. This is a different language to me. Any help would be great!

<?php
$conn_id = ftp_connect("ftp.aphrodite.WEBSITE.net/exporting/xml/products.xml");
$login_result = ftp_login($conn_id, "USERNAME", "PASSWORD");

if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
exit;
} else {
echo "Connected";
}

// get the file
$local = fopen("products.xml","w");
$result = ftp_fget($conn_id, $local,"httpdocs/products.xml", FTP_BINARY);

// check upload status
if (!$result) {
echo "FTP download has failed!";
} else {
echo "Downloaded";
}

// close the FTP stream
ftp_close($conn_id);
?> 

If I do not use the full url to the ftp file I do not get a login when using a browser.

  • 写回答

1条回答 默认 最新

  • drrc61668568 2017-03-14 21:42
    关注

    You supplied a wrong parameter to ftp_connect(), this function accept as parameter the hostname, not url.

     $conn_id = ftp_connect("ftp.aphrodite.WEBSITE.net");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助