TechJunkie is a BOX20 Media Company

Home Web Basic Windows FTP Command Line 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.

10 Ways To Make Windows XP Look And Feel Better

Read Next 

3 thoughts on “Basic Windows FTP Command Line Scripting”

SenHu says:
>> If someone found the scripting file in your C:\WINDOWS directory, they’ve got your FTP username and password.

This is not correct. One solution is already proposed above (don’t allow access to the batch file to anyone else but the author). But, that then makes it impossible to write a batch file usable by all.

I use this script.

http://www.biterscripting.com/helppages/SS_FTPUpload.html

It replicates the entire local directory to the FTP server. It creates subdirectories as necessary. And the good thing is, the FTP login and password are not hard-coded in the script. They are supplied by each user, when calling the script, as follows.

script “C:/Scripts/SS_FTPUpload.txt” ftpserver(“ftp.mycompany.com”) ftplogin(“login”) ftppassword(“password”)

Each user supplies his/her own login/password, making the script usable by all.

Jason Faulkner says:
>>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.

The security on a batch file is no different than the security of any other file… just set the properties so that only yourself (and obviously Administrators) can read it and you are all set. No need for the file to be in the Windows directory, it can be anywhere you like.

I’ve been using this method for over a year as a way to automate moving our backups off-site. My script runs on a Terminal Server and I have the security of the BAT file locked down so that standard users cannot access it.

Mark says:
FTP is an obsolete and outdated protocol.
Anyone using FTP should seriously consider using WebDAV.
Since DAV works over HTTP, you get all the benefits of HTTP that FTP cannot provide. For example: strong authentication, encryption, proxy support, and caching. It is true that you can get some of this through SSH, but the HTTP infrastructure is much more widely deployed than SSH. Further, SSH does not have the wide complement of tools, development libraries, and applications that HTTP does.
DAV transfers (well, HTTP transfers) are also more efficient than FTP. You can pipeline multiple transfers through a single TCP connection, whereas FTP requires a new connection for each file transferred (plus the control connection).
Do a Google search for BarracudaDrive, which is an easy to use WebDAV server.
http://barracudaserver.com/products/BarracudaDrive/FileServer.lsp
You do not need a client if using Windows or Mac since a client is integrated into the operating system.

Leave a Reply

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


Adam

Dec 10, 2008

643 Articles Published

More