Batch script a file via FTP
Dirty little Windows hacks that only be done in crude DOS batch script still crop up on a regular basis. Here's one that vexes many hardened hackers: What is the simplest way to send a file to an FTP server using a batch script?
@echo off
: Collect data from a database in CSV file
echo Removing file if it already exists...
del myfile.csv
echo Done.
echo Extracting data...
osql -E -d dxtb -Q "select stuff from sometable" -s "," -o myfile.csv
echo Done.
: Send file to FTP server
echo Sending extracted data...
@ftp -i -s:"%~f0"&GOTO:EOF
open myftpserver
myuserid
mypassword
put myfile.csv
disconnect
bye
Ignore all error warnings that FTP creates. Don't ask what the line @ftp -i -s:"%~f0"&GOTO:EOF does, but it works on 2003/2008!
| Next > |
|---|


