Reputation: 35
I'm trying to upload a png file with a batch file:
@ECHO OFF
echo user MYUSERNAME>> ftpcmd.dat
echo MYPASSWORD>> ftpcmd.dat
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
The upload works, but the png file is always corrupted.
What can I do?
Thanks and Greets Thorsten
Upvotes: 0
Views: 22
Reputation: 80113
The default mode for ftp put
is ASCII so the file will be terminated at the first x1a
(^Z) character (an ancient EOF used since CP/M)
Before the put
command, add an extra line
echo binary>> ftpcmd.dat
to switch to binary mode.
It may be easier to use
@ECHO OFF
(
echo user MYUSERNAME
echo MYPASSWORD
echo binary
echo put C:\1234.png
echo quit
)>ftpcmd.dat
ftp -n -s:ftpcmd.dat my-ftp-server.com
del ftpcmd.dat
pause
which will gather the output of the echo
es within the parentheses and output them to a new file ftpcmd.dat) (single
>` - create new file; double appends or creates)
Upvotes: 4