FTP

File Transfer Protocol has been around for a very long time and is still very much in use today. The file transfer protocol is used for transferring files around the Internet.

A lot of people mistakenly attach big files to email, but email was never meant to handle big file attachments. Email was to send electronic mail between two individuals, not to send entire documents.

If you need to send big files you need to FTP them or transfer them by essentially a different courier method/mechanism.

FTP is another client/server implementation in Linux. On the server the FTP daemon on the client an FTP client.

A lot of Web-browsers behave like ftp clients allowing you to connect to a ftp server rather than a http server.

You can either use FTP as a real user with a password, or you can FTP as a user "anonymous".

When you use anonymous FTP, you are not normally prompted for a password.

If you are, you can use a password like <yourname>@. Leaving off the domain after the @ will result in your domain (from which you are connecting), being affixed to the password. They (the ftp server people) do not check this, so many people just type in <character>@. In that case that would allow me to anonymously log in from the client to a server.

Once on the server you really have just a big file repository with a whole lot of files that we can send and essentially I would "get" (which is the command to download a file) file from the server or I could "put" (which is a command to upload files to a ftp server) files to the server. And it's important that you understand that when you connect to an FTP site, you are getting files from the site and when you want to send something to the site, you put file to that site.

One of the problems here is that if you do a pwd, for example, on your site you are not printing the working directory on your local Linux machine; you're printing the working directory on the remote site. If you say "cd linuxdistribution", you're not changing directory on the local client side, you are actually changing directory on the remote side and if you want to change directory on the local side, you say "lcd /home/dir" which changes directory on the local side.

This is what often confuses people when they first start using FTP, is they'll say cd to my home directory and it will say no such file directory and they get confused because they think that the directory is there, they know it's there. But it won't allow them to change directories and that's because when you cd you're changing directory on the remote server side rather than on the local client side.

So, it's just worth bearing in mind FTP to 192.168.1.1 - let's say - and it would ask you for a user and you could then say anonymous and it would ask you for password and you would say Hamish (or whatever your username is) @, (and give it your email address) and then from there you would be logged in.

You would be logged in to the pub directory - you can do a listing and you can change directory to pub/Linux/distribution and then from the FTP site you can download all the distribution files that you need.

Similarly, if there was an upload area where you could put files, you could say put /pub/ftp/upload and that would actually send a file to the FTP server. A lot of FTP servers don't allow you to upload files to the server, as they are primarily for download, but theoretically you are able to upload files with FTP as well.

So that's the 30 second guide to using FTP and I've given you some examples and exercises where you can actually go and try using FTP to get and put various files.

ftp 192.168.10.144
Connected to 192.168.10.144.
220 debian.zoo.org.za FTP server \
                (Version 6.4/OpenBSD/Linux-ftpd-0.17) ready.
Name (192.168.10.144:riaan): anonymous
331 Guest login OK, send your complete e-mail address as password.
Password:
            

You need to enter your password here now.

ftp&gt; ls
150 Opening ASCII mode data connection for '/bin/ls'.
total 144
-rw-r--r--    1 test     visitor       266 Feb 16 14:25 .alias
-rw-------    1 test     visitor      4265 Mar 17 13:35 .bash_history
-rw-r--r--    1 root     root          701 Feb 27 10:31 zoo.org.za.zone.gz
226 Transfer complete.

            

Perform a listing of your LOCAL directory (the directory on the machine from which you are connecting to the ftp server). For this you will need to shell out of your current ftp session. Shelling out will mean starting a shell environment, placing the ftp client in the background. You can shell out with a "!" command. The ! Command actually runs a command in a shell, so if you wish to shell out to run a number of commands, you will need to start another shell as follows:

	!/bin/bash
            

This will give you a prompt at which you can type commands into your LOCAL machine. Note, you cannot shell out onto the remote machine as that would have serious security implications.

Getting and putting files in an ftp session can be done using one of two modes: binary and ascii. Many modern ftp clients will switch themselves automatically into binary or ASCII mode depending upon the file that is being put/got. However, to make sure, you can switch the mode yourself using the "type" command. Thus, a

	type binary
            

will ensure that the client is expecting a binary file as the next file that is up/down-loaded.

ftp&gt; get bind9.tar.gz
local: bind9.tar.gz remote: bind9.tar.gz
227 Entering Passive Mode (192,168,10,144,4,15)
150 Opening BINARY mode data connection for \
                'bind9.tar.gz' (2844 bytes).
100% |************************|  2844     \
                265.69 KB/s    00:00 ETA
226 Transfer complete.
2844 bytes received in 00:00 (69.23 KB/s)
ftp&gt; put /home/riaan/Python_for_.NET_whitepaper.pdf \
                ./Python_for_.NET_whitepaper.pdf
local: /home/riaan/Python_for_.NET_whitepaper.pdf remote: \
                ./Python_for_.NET_whitepaper.pdf
227 Entering Passive Mode (192,168,10,144,4,17)
150 Opening BINARY mode data connection for \
                './Python_for_.NET_whitepaper.pdf'.
100% |************************| 52773       \
                0.98 MB/s    00:00 ETA
226 Transfer complete.
52773 bytes sent in 00:00 (743.59 KB/s)
            

Exercises:

  1. ftp to ftp.is.co.za as an anonymous user and look inside the Debian directory. Obtain a listing of all files in this directory

  2. Change directory to the pool/f/fortune-mod/ directory and obtain one of the fortune binaries.

  3. Perform a local directory change to the /tmp directory and obtain another of the fortune files.

  4. Obtain a listing of the ftp commands that are available on your ftp client using the "?" operator (of type "help").

  5. Get a number of files in a single operation (hint: get help on the mget command).

  6. Ftp to yourself (localhost) and log in as your user. This time we are not logging in as the anonymous user.

  7. Obtain a litsing of all files in your directory you are connected to.

  8. Put a file from the /tmp directory (perhaps one of the fortune programs you just downloaded from Internet Solutions (ftp.is.co.za) into your home directory.

  9. Put many files at once into your home directory.

  10. Quit you ftp session and look in you home directory to verify the files are there.