All Posts Tagged With: "scripting"

Basic Windows FTP Command Line Scripting

Sometimes there is a need to login via FTP from the command line in Windows. Maybe you just need to login to make a quick upload or download.

This tutorial will show you how to make a quick login script that will login you into your FTP server without having to type it in.

To do this, we write two text files (one script, one batch) and place both of them in the C:\WINDOWS folder for "launch from anywhere" access since C:\WINDOWS is by default in the resident path.

Step 1: The FTP Scripting File

Open up Windows Notepad and enter the following 3 lines:

open [your ftp server address here]
[your ftp username]
[your ftp password]

Here’s another way of looking at it:

open ftp.example.com
myusername
mypassword

Save this file as C:\WINDOWS\goftp.txt

Step 2: The Batch File

Open up Windows Notepad again, create a new text file and enter the following two lines:

CD C:\WINDOWS
ftp -s:goftp.txt
exit

Step 3: Run the batch file

The files are already in the system path so you can directly launch this from the Run dialog box.

Click Start then Run, type goftp and click OK.

A command prompt window will appear and log you right in.

When you type exit to log off from the FTP server, the window will automatically close (that’s what the "exit" line is for in the batch file).

Quick question answered: Can’t all this be done in a single batch file?

Answer: No. When the batch file calls the FTP application it cannot execute commands within the FTP session. That’s why you need an additional text file to "carry in" commands with.

If your batch file looked like this:

CD C:\WINDOWS
ftp ftp.example.com
username
password

..this is wrong. The batch file will stop right after the "ftp ftp.example.com" line and will not input the username or password. And when you exit the FTP session you’ll get a command line error because your FTP username and password aren’t Windows executables.

One final note: This is obviously not secure whatsoever. If someone found the scripting file in your C:\WINDOWS directory, they’ve got your FTP username and password.

Only do scripting like this on a computer nobody else uses but you.