donglinxia1541
donglinxia1541
采纳率0%
2017-03-14 21:30 阅读 126
已采纳

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 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");
    
    点赞 评论 复制链接分享

相关推荐