Fix Zip Corrupting After Uploading It Via FTP
I came across a problem recently when uploading a Zip file via FTP. The Zip file would open fine before sending, however trying to open and extract it on the remote server resulted in an error. Inparticular, when opening the file with WinZip the error was as follows:
Error: central directory not found
The problem turned out to be the mode in which the file was being transferred. There are two modes of upload when it comes to putting files with FTP: ASCII or Binary. Initially I was using the ASCII mode which is primarily intented to handle information stored in text. Simply changing the mode to Binary and re-uploading the Zip file then allowed me to extract it successfully.
If you’re using a bit of software to transfer files then this setting will be in the preferences and will normally be set by default. In my scenario I was performing the upload using PHP so the following change was needed to correct the mode used:
ftp_put($conn, $remoteFile, $localFile, FTP_ASCII);
ftp_put($conn, $remoteFile, $localFile, FTP_BINARY);