I have a PHP script that works when using ftp_connect, but when using ftp_ssl_connect it doesn't work.
Does anyone know why?
When running the script on a remote server that only requires ftp_connect, the script below works without issue. But as soon as I switch to a server requiring ftp_ssl_connect the script hangs and I end up with a 504 error with no indication of what went wrong.
I have attempted debugging by removing all the script except for the login, and the login seems to work on its own, but when I add in any requests beyond login it causes a 504
<?php
// set up basic ssl connection
$ftp = ftp_ssl_connect('myremotesite.com');
// login with username and password
$login_result = ftp_login($ftp, 'username', 'password');
if (!$login_result) {
// PHP will already have raised an E_WARNING level message in this case
die("can't login");
}
// get list of files on given path
$files = ftp_nlist($ftp, '/1668161919_DATA/*add.zip') or
die("Could not find file");
$mostRecent = array(
'time' => 0,
'file' => null
);
foreach ($files as $file) {
// get the last modified time for the file
$time = ftp_mdtm($ftp, $file);
if ($time > $mostRecent['time']) {
// this file is the most recent so far
$mostRecent['time'] = $time;
$mostRecent['file'] = $file;
}
}
ftp_get($ftp,
"/home/mysite/public_html/wp-content/uploads/data-zipped/target.zip",
$mostRecent['file'], FTP_BINARY);
ftp_delete($ftp, $mostRecent['file']);
ftp_close($ftp);
?>