Friday, September 10th, 2010

Command Line FTP

Thursday, November 20th, 2008 by Jonathan Lau

Today, I will be teaching you how to upload and download files through the command line FTP client. This client should be available on most versions of Windows as well as on Linux.

Why learn command line FTP?

Firstly, command line FTP is useful for uploading or downloading files on a public computer terminal without a GUI client. Most public terminals would probably not allow you to install new applications. Command line FTP would be ideal if you just want to upload a file or two quickly once you’ve learnt about it.

How to use it?

The following image is an example of a typical session in the command line FTP.

ftp

To start the command line FTP client, launch “ftp” from run.

runftp

Once you click OK, you should see a black window with the prompt “ftp >”.

The Commands

Connect to remote FTP server (open / o)

Before you can start uploading or downloading files, you first have to connect to the ftp server.

To do so, use the “open” command, or “o” for short.

Type in “o yourwebhost.com” and press enter.

If nothing went wrong, you should be prompted with your username and password from the FTP server. Your password will be masked for security reasons when you type it in, so don’t worry if you don’t see what you’re typing.

Print working directory on the remote machine (pwd)

Once you’re logged in, you might want to know the directory you are in. Typing “pwd” would print the current working directory on the remote machine. You should get a response similar to this:

257 “/” is the current directory

Change working remote directory (cd)

If you would like to change your working directory, simply type “cd anotherdir”. The new directory could be an absolute or relative path. You should expect a response similar to:

250 CWD command successful

List contents of remote directory (ls / dir)

To list the contents of your current remote working directory, type in “ls” or “dir”. Generally speaking, has the same purpose, but dir would print more information, such as the linux permission of the files and the file size. “ls” would only give you the list of files.

Change working local directory (lcd)

The “lcd” command works like “cd”, just that it changes the local working directory instead of the remote working directory.

Set the transfer mode (binary / ascii)

Before you start uploading, you should set the transfer mode. If you are uploading text files (including php and other codes), you should set the transfer mode to ascii, though binary will probably work fine. Simply type in “ascii” and hit enter.

If you are uploading images or executables, it is important to set the transfer mode to binary. Failing which, the uploaded image might not display correctly. Just type in “binary” and hit enter.

Uploading files (put / mput)

To upload a single file, type in the following command,

put “yourfile.html”

Again, you could use absolute or relative paths. Typing the above command will upload yourfile.html from the current local working directory.

To upload more than one file at once, you can use the “mput” command. Type in “mput” followed by the files you want to upload, separated by a single space. If your filename contains a space, remember to wrap the filename in quotations.

mput file1.html file2.html file3.html

FTP will confirm if you want to upload the files. You should see the prompt below, simply press enter to confirm.

mput file1.html?

You could also use “mput” to upload all files in the local working directory, or all files with a specific extension by using the wildcard. For example, type “mput *.*” to upload all the files in the directory, and “mput *.txt” to upload all text files.

Downloading files (get / mget)

Downloading files is simply the reverse of uploading files. Thus, the commands work the same way. Files will be downloaded to your local working directory. To download a file, simply type

get file.html

Since its similar to uploading files, I will move on to the other functions.

Delete remote file (del / mdel)

This command is used to remove files from the server. Again, the usage of this command is similar to the command to upload files. Just type “del yourfile.html” to remove it from the server.

Make directory on the remote machine (mkdir)

To create a directory on the remote sever, type in “mkdir your_new_dir”. A directory should be created once you hit enter.

Remove directory on the remote machine (rmdir)

To remove a directory on the remote sever, type in “rmdir deletethisdir”. The directory should be deleted once you hit enter. This command will only work if the directory is empty.

Changing Linux file permissions (literal site chmod)

File permissions on Linux is usually categorised into read, write and execute for the owner, group and world. It is represented by a 3 digit number. To change file permissions, type in the following command where 777 is the new file permission and yourfile.txt is the file you are setting the permissions on:

literal site chmod 777 yourfile.txt

Terminate ftp session and exit (bye)

To end the session, type “bye”. You will be disconnected from your FTP server.

Command line arguments

FTP.exe also has its own set of command line arguments. If you type “ftp –help” in a command prompt, you should see a list of commands. FTP also has an option to run commands from a text file. However, I will only cover that another day. This should be enough for you to start uploading and downloading files from your FTP server!

Tip: Typing “ftp yourhost.com” in run will get ftp to connect to yourhost.com automatically.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Comments

Receive updates on the comments through RSS 2.0!

There are no comments so far...

Be the first one to comment!

Leave a Reply