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.

Free eBook!

Like what you read?

If so, please join over 28,000 people who receive our exclusive weekly newsletter and computer tips, and get FREE COPIES of 5 eBooks we created, as our gift to you for subscribing. Just enter your name and email below:

Post A Comment Using Facebook

  • http://barracudaserver.com/products/BarracudaDrive/FileServer.lsp Mark

    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.

  • Jason Faulkner

    >>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.

  • SenHu

    >> 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.

What’s Your Preference?

Daily Alerts

Each day we send out a quick email to thousands of PCMECH readers to notify them of new posts. This email is just a short, plain email with titles and links to our latest posts. You can unsubscribe from this service at any time.

You can subscribe to it by leaving your email address in the following field and confirming your subscription when you get an email asking you to do so.

Enter your email address for
Daily Updates:

Weekly Newsletter

Running for over 6 years, the PCMECH weekly newsletter helps you keep tabs on the world of tech. Each issue includes news bits, an article, an exclusive rant as well as a download of the week. This newsletter is subscribed to by over 28,000 readers (many who also subscribe to the other option) - come join the community!

To subscribe to this weekly newsletter simply add your email address to the following field and then follow the confirmation prompts. You will be able to unsubscribe at any time.

Enter your email address for
Free Weekly Newsletter: