kk4iku Posted September 22, 2017 Share Posted September 22, 2017 I am downloading a file from an FTP site and sometimes the file will not be there how can I exit the PHP gracefully ? If there is not a file I get the below error message. ftp_get(): Requested action not taken. Message not found. Error downloading sample.txt if (ftp_get($ftp_conn, $local_file, $ftp_path.$server_file, FTP_ASCII)) { echo "Successfully written to $local_file."; } else { echo "Error downloading $server_file."; ftp_close($ftp_conn); exit; } ftp_close($ftp_conn); Link to comment Share on other sites More sharing options...
ginerjm Posted September 22, 2017 Share Posted September 22, 2017 Is that the official message or something you created? Basically - there s/b more of a message. Link to comment Share on other sites More sharing options...
requinix Posted September 22, 2017 Share Posted September 22, 2017 Requested action not taken. Message not found.That's not from PHP. Probably the remote FTP server. You already have the error message and an exit; so what are you asking for? Link to comment Share on other sites More sharing options...
kk4iku Posted September 22, 2017 Author Share Posted September 22, 2017 so this message is from the FTP server "ftp_get(): Requested action not taken. Message not found.". can I hide it so the user only gets my message? Link to comment Share on other sites More sharing options...
requinix Posted September 22, 2017 Share Posted September 22, 2017 Make your code smart enough to know if the file exists: use ftp_nlist to get the contents of the parent directory, then check that the file requested is in there. You should also change your production environment (the php.ini/whatever settings) to log errors (set error_log if not already set) instead of displaying them (turn off display_errors). Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.