cURL FTP 连接

发布于 2025-01-03 09:05:36 字数 1014 浏览 0 评论 0原文

我们的服务器上运行着一个 cron 作业,它从 MeteoConsult 下载数据,MeteoConsult 是一家荷兰天气报告公司……

总之,基本上脚本通过 cURL 使用 FTP 下载 XML 文件,然后使用该文件进行解析简单XML。一两周前,它决定随机死亡并扼杀了我们观看天气的乐趣。我一无所知。 FTP数据正确并且已经过验证。 Meteo 服务器不会阻止运行 cron 作业的服务器的 IP 地址。

为什么开发人员使用 cURL 通过 FTP 下载文件对我来说确实是一个谜。当我在不同的服务器上运行该脚本时,它似乎可以工作。

有了这些信息,我认为要么我们使用“老式”方式,并且无法使用新的 cURL / PHP 版本(尽管我找不到任何相关信息),要么我们服务器的防火墙阻止了连接。

这是脚本(部分):

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"ftp://username:[email protected]/file.xml");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 300);
curl_setopt($curl, CURLOPT_FTP_USE_EPSV, 0);

$xml = curl_exec($curl);
$status = curl_getinfo($curl);
curl_close($curl);

// At this point, $xml is NULL

这个脚本有什么问题吗?如果没有,你们知道问题出在哪里吗?

PHP version: 5.2.12
libcurl version: 7.20.0

非常感谢。

We have a cron-job running on our server, that downloads data from MeteoConsult, which is some dutch weather-report company... thing...

Anyway, basically the script downloads an XML file using FTP via cURL which then gets parsed using SimpleXML. A week or two ago, it decided to die randomly and kill our joy of watching the weather. I'm clueless. The FTP data are correct and have been verified. The Meteo server doesn't block the IP address of the server the cron-job is running on.

Why the developer used cURL to download a file over FTP is truly a mystery for me. When I run the script on a different server it seems to work.

With that information, I assume that either we're using an "old fashioned" way and doesn't work with new cURL / PHP versions though I couldn't find any information about that, or our server's firewall is blocking the connection.

Here's (a part) the script:

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"ftp://username:[email protected]/file.xml");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 300);
curl_setopt($curl, CURLOPT_FTP_USE_EPSV, 0);

$xml = curl_exec($curl);
$status = curl_getinfo($curl);
curl_close($curl);

// At this point, $xml is NULL

Is there anything wrong with this script? If not, do you guys have an idea what the problem could be?

PHP version: 5.2.12
libcurl version: 7.20.0

Many thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

染墨丶若流云 2025-01-10 09:05:36

看看 使用 ftp 下载文件中提供的答案 我

基本上,您需要将 URI 和身份验证设置分开,如下所示:

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "ftp.meteocon.nl/file.xml"); #input
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FILE, $file); #output
curl_setopt($curl, CURLOPT_USERPWD, "$_FTP[username]:$_FTP[password]");
curl_exec($curl);

还没有对此进行测试,但希望它有所帮助。

Take a look at the answer provided at download a file from ftp using curl and php

Basically you need to separate out the URI and the authentication settings like so:

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "ftp.meteocon.nl/file.xml"); #input
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FILE, $file); #output
curl_setopt($curl, CURLOPT_USERPWD, "$_FTP[username]:$_FTP[password]");
curl_exec($curl);

I have not tested this, but I hope it helps.

ˇ宁静的妩媚 2025-01-10 09:05:36

看来问题与 IPv6 FTP PASV 相关。尝试打开/关闭(或测试完全删除)CURLOPT_FTP_USE_EPSV 选项。
您可以查看以下内容以获取更多信息:IPv6 FTP PASV 问题

It seems that the problem is IPv6 FTP PASV related. Try to turn on/off (or test as completelly remove) the CURLOPT_FTP_USE_EPSV option.
You can check this for more info: IPv6 FTP PASV problems

指尖上的星空 2025-01-10 09:05:36

主机最近加强了服务器的安全性。他们必须将该 URL 添加到白名单中。

感谢所有的答案。

The host recently tighten up the security of their servers. They had to add the URL in the white-list.

Thanks for all the answers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文