A Beginner’s FTP Command Tutorial For Ascii or Binary File Transfers
FTP stands for File Transfer Protocol. It is a simple and secure way to exchange files over the Internet. There are two players involved in any FTP transfer – the server or the site which is hosting the files and the client which contacts the server and requests to transfer a file. You can either use your browser or you can download a specific software to run as a FTP client.
What you will need:
- The address of the FTP server you wish to communicate with. This can be an IP address or a domain name.
- The login credentials for a FTP account on the server (you don’t need this for anonymous or public FTP).
- An FTP client.
Assuming you know the address and the login credentials, let’s straight away hop over to the FTP client. As I mentioned before you can either use your browser as a client or use dedicated FTP software. If you want to download the occasional file or two from FTP sites you are good to do so with a browser, just type in the address of the file and make sure you use ftp:// instead of the usual http://.
If on the other hand you are managing a site or required to constantly upload/download files and manage accounts on the server you should use a FTP client designed for the task. Here are your choices:
- Most operating systems have a built in command line FTP client with which you would have to get familiar with the commands.
- You can also use one of the GUI FTP clients: Firefox users can try FireFTP, or you can use FileZilla , built specially with FTP in mind.
It is easier to find your way around the GUI tools. A typical GUI client would have two panes, one showing the remote FTP directory and the other showing directories on your computer. There are buttons representing transfer between the two panes. Browse to the directories you want to transfer to/from like you would do inside Windows Explorer, click on the appropriate transfer button and the client takes care of the rest.
All the commands are issued transparently by the client without requiring you to issue them explicitly. While this may seem easier, it is always handy to know what is going on behind the scenes, which you can by trying out the commands yourself.
Let’s touch up the basic FTP commands, shall we?
First and foremost you need to connect to the host. Use ftp to connect to the host. The server would respond with some information including if anonymous access is allowed. If it isn’t, you will be required to enter a username and password for the FTP account on the server.
Go ahead and enter those details. If you don’t know your username or password, you would have contact the administrator of the site or create a new FTP user (if you are the administrator).
After a successful login you can perform any desired operations on the files. You can always use the help to get a list of available commands or get help on any command as well.
Let us now see how you can perform the basic file operations over FTP:
1. Moving around
- To get a directory listing both ls and dir work.
- You can change directories using the ubiquitous cd command. e.g. cd www changes to the www directory, To change to a local directory (i.e. a directory on your computer) instead use the lcd command.
- To know which directory you are currently working in use the pwd (present working directory) command.
- You can create directories using the mkdir <dir-name> command, remove directory using rmdir <dir-name> .
- To delete a file use the delete <filename> command, rename files using rename <old-name> <new-name> .
2. Set File Transfer type
- If you are going to transfer text files (includes txt, html, shell scripts, css files etc) you need to set the file transfer mode to ascii using ascii command.
- On the other hand if you are going to transfer binary files (like images, pdf, MS office files, compiled code or executables etc) you need to set the file transfer mode to binary using binary command.
3. Transferring files
- To upload files to the server use the put command. e.g. put style.css would upload style.css from your local directory to the remote directory. Not that put doesn’t allow you to use wildcards, use mput instead, if you want to use wildcards.
- Similarly to download a file you can use the get <filename> or the mget <filenames/wildcards> commands.
4. Creating your own FTP server
If you pay a hosting company for server space, they generally have things configured beforehand and some even create accounts for you. You can always use the management panel to create and edit FTP accounts and some settings. You would have to poke around the management panel your hosting company is providing you with.
If you want to create an FTP server on your home network some configuration is needed. Windows user can try the Filezilla server. Its great and simple to use. Linux users have plenty of options out of which vsftpd is pretty straighforward and feature rich.
Once you have configured the server you can access your files from any computer on your home network, using the IP address of the FTP server. If you want to be able to access your server from across the Internet you would require a static IP or perhaps you could look into something like dyndns (which we discussed briefly while configuring remote access to your torrents ).
That’s it, you have enough knowledge to get you started and help you along whenever working with FTP. Let us know if you use some other tools for similar purposes.