Cron 到 FTP 文本文件 - PHP FTP 失败

发布于 2024-12-29 01:25:10 字数 862 浏览 0 评论 0原文

我目前在 Cron 文件中使用 PHP 来解析 MySQL 数据库中的记录,并将数据格式化为第三方规范(CSV 文件)。

我生成文本文件没有问题,但是当我访问 FTP 时,ftp_connect() 返回 false。

它已经工作了一段时间;在我的浏览器中运行时的 cron 文件显示传输成功。现在 ftp_connect() 突然失败(返回 false,在这种情况下我回显“无法传输文件。(path/file.txt): FTP 失败:无法连接到 ftp.website.com”)。

上面的错误语句是由此生成的:

try {
    $conn_id = $this->connect_ftp($host, $username, $password, $port);
} catch(Exception $e){
    throw new Exception('<strong>FTP failure:</strong> ' . $e->getMessage());
}

and connect_ftp():

$conn_id = ftp_connect($host);
if($conn_id === false){
    throw new Exception('Failed to connect to '.$host);
}

我已经单独检查了目标服务器,它们一直在零星地接收文件,但在过去一周一直持续(即最近的是 21 号,然后是 19 号),尽管 cron 每晚都会运行。

我循环遍历一系列文件格式和 FTP 凭据来连续创建文件、将其保存在本地,然后传输它。

我需要用 sleep() 来中断传输吗?

I am currently using PHP in a Cron file to parse records from a MySQL database, and format the data to third-party specifications (CSV files).

I am generating the text files with no problem, but when I go to FTP, ftp_connect() is returning false.

It was working for a while; the cron file when run in my browser was showing successful transfer. Now it is suddenly failing on ftp_connect() (returning false, on such a condition I echo "Failed to transfer file. (path/file.txt): FTP failure: Failed to connect to ftp.website.com").

The above error statement is generated from this:

try {
    $conn_id = $this->connect_ftp($host, $username, $password, $port);
} catch(Exception $e){
    throw new Exception('<strong>FTP failure:</strong> ' . $e->getMessage());
}

and connect_ftp():

$conn_id = ftp_connect($host);
if($conn_id === false){
    throw new Exception('Failed to connect to '.$host);
}

I have checked the target servers individually, and they have been receiving files sporadically, but consistently over the past week (ie. most recent is the 21st, then the 19th), although the cron runs every night.

I am looping through an array of file-formats and FTP credentials to successively create the file, save it locally, then transfer it.

Do I need to break up the transfers with sleep()?

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

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

发布评论

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

评论(1

疾风者 2025-01-05 01:25:10

您尝试过 php.net/manual/en/function.ssh2-scp-send.php 吗?我们在远程 ftp 方面遇到了一些问题,因此改用 ssh2_scp_send。从那以后就没有出现过问题

Have you tried php.net/manual/en/function.ssh2-scp-send.php? We had some issues with remote ftp and went with ssh2_scp_send instead. Haven't had problems since

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