I am using the following format in php code to download files from ftp server.
file_put_contents(
$filePath.$fileName, file_get_contents(
true == (
$data = @
file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
)
?
file_put_contents('xyz#123.csv', $data)
:
exit;
Use this
<?php
// define some variables
$local_file = 'filename.jpg';
$server_file = 'filename.jpg';
$ftp_server="www.abc.com";
$ftp_user_name="username";
$ftp_user_pass="password";
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
}
else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);
?>
Try:
$output = exec("wget -N ftp://username@ftp.server.com/path/to directory/file 2>&1 |grep 'filename w/o extension'|grep -v ftp|grep -v =");
print $output <to check if file downloaded or not>