Using FTP Coding corrupts uploaded files

Much has been written about using the FTP protocol in code to upload files to websites. My problem is different, and is as follows:

I am using the following files to upload a batch of PDF files to my website:

Put SampleFile.pdf

ftp -i -s:FTP_cmd_Example.txt

Using these two files, the PDF files do upload successfully;  however, after the uploading, the files become corrupted. I tried this with PDF files and Word files.

In the attached file, I show the before-and-after screenshots of the uploaded PDF file. I also show the error message when trying to open the corrupted Word file (after it had been uploaded).

(1) When I upload the same files using an FTP client (Filezilla), the corruption does not occur.
(2) When I use the code to upload the files to a test bed site, the corruption does not occur
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark BullockQA EngineerCommented:
Before the put command, execute the binary command.
This will do the file transfer in binary mode (8 bits per byte) rather than ASCII (7 bits per byte).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dave BaldwinFixer of ProblemsCommented:
To expand on Mark's comment, Filezilla, CoreFTP, and other FTP client programs have lists of file types that they will automatically switch to either binary or ascii transfer modes.  I believe the default for them is to use binary mode but in your code, you have to make that switch yourself.
ms3930Author Commented:
Mark: Adding 'binary' to the FTP_cmd.txt file solved it!

Dave: Thank you for the additional clarification.
Dave BaldwinFixer of ProblemsCommented:
You're welcome.  The only practical use of ASCII mode is to take advantage of the automatic end-of-line conversion for text files that is normally done between Windows, Mac, and Linux/Unix systems.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.