Windows Batch FTP Routine

Here is some example code to connect to an FTP server and run the commands that follow.

@echo on

%windir%\system32\ftp.exe -n -s:"%~f0" server.com
goto done
user myusername
mypassword
cd /home/directory/public_html
ls -al
quit
:done
pause

The key to this working are the following:

The -n switch allows you to not be prompted for a username upon connection.
The -s:”%~f0″ says to use the rest of the file as the commands to execute
The goto command is not a valid FTP command, so the FTP server ignores it.

So you have the script using the Windows FTP utility to connect to a server and a routine running your commands. You can even extend off of this.

This entry was posted in Windows and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">