简体   繁体   English

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

[英]PHP Script to Get File From Another Server and Save on My Server

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. 我一直在玩一些php脚本,试图首先至少使php文件连接到我的发行商文件上的ftp,然后再将其保存到我的文件中。 I was going to save this as a cron to run this script daily. 我打算将其保存为cron以每天运行此脚本。 I can't get it to connect to the distributors ftp. 我无法连接到分销商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. 他们的ftp访问是ftp.aphrodite.WEBSITE.net文件的确切位置是ftp.aphrodite.WEBSITE.net/exporting/xml/products.xml我可以使用filezilla和浏览器访问它。 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. 如果我不使用ftp文件的完整URL,则在使用浏览器时无法登录。

您为ftp_connect()提供了错误的参数,此函数接受主机名而不是url作为参数。

 $conn_id = ftp_connect("ftp.aphrodite.WEBSITE.net");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM