I'm trying to download the most recent file with the extension add.zip via ftp
I'll preface this by saying I am not well versed in php and have created this frankenstein piece of code from a scattering of other codes.
here is my code
<?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);
?>
After some testing
<?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 === TRUE) {
echo 'woot!';
} else {
echo 'doh!';
}
Returns a woot
but
// set up basic ssl connection
$ftp = ftp_ssl_connect('myremotesite.com');
// login with username and password
$login_result = ftp_login($ftp, 'username', 'password');
// get list of files on given path
$files = ftp_nlist($ftp, '/1668161919_DATA/*add.zip');
if ($files === TRUE) {
echo 'files found!';
} else {
echo 'doh! files not found';
}
?>
Cause a 504 error with no further information.
What am I doing wrong?
When I copy the URL to clipboard in FileZilla the data is sftp://[email protected]/1668161919_DATA
Am I even close to getting this right?
When I have tried using similar FTP file downloads in the past, it was with
ftp_connect
This is the first time I have been forced to use
ftp_ssl_connect
Ok, so I set up a testing environment and ran the script using ftp_connect instead of ftp_ssl_connect and the code worked fine.
I think I need to define my port as 22. But
$ftp = ftp_ssl_connect('myremotesite.com','22')
doesn't work. Can anyone assist?
ftp_login
. On which does it hang? Doesftp_nlist
work? + Never post any information in comments. Always edit everything you know/you find into your question.