使用批处理文件上传PNG文件后文件损坏,如何解决?
Hey Thorsten,
Sorry to hear your PNG files are getting corrupted after uploading with your batch script—let’s get this sorted out quickly.
The root cause here is that FTP defaults to ASCII transfer mode, which automatically modifies characters like line breaks and carriage returns in your file. Since PNGs are binary files (not plain text), this character translation mangles the file structure and leads to corruption. The fix is simple: we just need to force FTP to use binary transfer mode.
Here’s your updated batch script with the critical addition:
@ECHO OFF echo user MYUSERNAME>> ftpcmd.dat echo MYPASSWORD>> ftpcmd.dat echo binary>> ftpcmd.dat :: This line enables binary transfer mode echo put C:\1234.png>> ftpcmd.dat echo quit>> ftpcmd.dat ftp -n -s:ftpcmd.dat my-ftp-server.com del ftpcmd.dat goto Ende :Ende pause
What’s different?
We added the binary command right after logging into the FTP server. This tells the server to transfer the file as raw, unmodified binary data—no character translation, so your PNG stays intact.
Quick verification steps:
- After uploading, compare the file size of the remote PNG with your local
1234.png—they should be exactly the same if the transfer worked correctly. - If you have a GUI FTP client handy, try manually uploading the PNG with binary mode enabled to confirm your server supports this (most standard FTP servers do).
That should fix the corruption issue entirely. Let me know if you hit any other bumps along the way!
内容的提问来源于stack exchange,提问作者user3322859

