简体   繁体   中英

Cron to FTP text files - PHP FTP failure

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()?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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