I am using the following format in php code to download files from ftp server.
file_put_contents(
$filePath.$fileName, file_get_contents(
ftp://username:password@server_name/folder_name/xyz#123.csv.zip
)
);
I am getting an 550 error as the file name contains '#'. How to avoid the error. Also what is the best PHP class to do different operations on FTP ?
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);
?>
true == (
$data = @
file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
)
?
file_put_contents('xyz#123.csv', $data)
:
exit;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With