next up previous
Next: FTP wildcards Up: Simple FTP Client Sessions Previous: Setting File Transmission Type

Navigating Directories and Listing Files

Having Logged to a machine you may want to navigate directories to find a file you wish to download or find a place to upload a file. Most FTP server only allow to upload files to specific directories, typically a directory called incoming is used.

You may also wish to naviagte you local file space in order to save a file to specific directory.

Finally you may wish to create directories on the server (if you have the correct permission) or locally.

Remote (Server side) FTP commands:

pwd
-- Print the name of the current working directory on the remote machine. For example:

ftp> pwd
257 "/pub" is current directory.

cd
remote-directory Change the working directory on the remote machine to remote-directory .

For example to change to a directory ex_gif do:

ftp> cd ex_gif 
250 CWD command successful.
ftp>

cdup
-- Change the remote machine working directory to the parent of the current remote machine working directory.

To see the effect of cdup we first are located in a sub directory and see this from a pwd command. We execute cdup and then do another pwd and we are in the parent pub directory:

ftp> pwd
257 "/pub/ex_gif" is current directory.
ftp> cdup
250 CWD command successful.
ftp> pwd
257 "/pub" is current directory.
ftp>

dir
[ remote-directory ] [ local-file ] Print a listing of the directory contents in the directory, remote-directory , and, optionally, placing the output in local-file . If no directory is specified, the current working directory on the remote machine is used. If no local file is specified, or local-file is -, output is sent to the terminal.

The following example list the files in the pub directory on the year1 Internet Computing FTP site:

ftp> dir
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
total 32
drwxrwxrwx   2 y1ftp       2048 Nov  8  1999 ex_gif
drwxrwxrwx   2 y1ftp       2048 Nov  8  1999 ex_hqx
drwxrwxrwx   2 y1ftp       2048 Nov  8  1999 ex_text
drwxrwxrwx   2 y1ftp       2048 Nov  8  1999 ex_uu
drwxrwxrwx   2 y1ftp       2048 Nov  8  1999 ex_zip
drwxr-xr-x   2 y1ftp        512 Oct 18  1999 exercise
drwxrwxr-x   2 gueftp      2048 Nov  5  1999 incoming
drwx--x--x   2 staff       1024 Nov 11  1999 marker
drwxrwxr-x   2 gueftp      2048 Nov 10  1999 test
226 Transfer complete.
489 bytes received in 0.0074 seconds (64.46 Kbytes/s)

ls
[ remote-directory | -al ] [ local-file ] Print an abbreviated listing of the contents of a directory on the remote machine. If remote-directory is left unspecified, the current working directory is used.

The -a option lists all entries, including those that begin with a dot (.), which are normally not listed. The -l option lists files in long format, giving mode, number of links, owner, group, size in bytes, and time of last modification for each file. If the file is a special file, the size field instead contains the major and minor device numbers rather than a size. If the file is a symbolic link, the filename is printed followed by "->" and the pathname of the referenced file.

If no local file is specified, or if local-file is -, the output is sent to the terminal.

Here is an example of ls -l for the year 1 FTP site:

ftp> ls -l
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
total 32
drwxrwxrwx   2 adm      y1ftp       2048 Nov  8  1999 ex_gif
drwxrwxrwx   2 adm      y1ftp       2048 Nov  8  1999 ex_hqx
drwxrwxrwx   2 adm      y1ftp       2048 Nov  8  1999 ex_text
drwxrwxrwx   2 adm      y1ftp       2048 Nov  8  1999 ex_uu
drwxrwxrwx   2 adm      y1ftp       2048 Nov  8  1999 ex_zip
drwxr-xr-x   2 adm      y1ftp        512 Oct 18  1999 exercise
drwxrwxr-x   2 adm      gueftp      2048 Nov  5  1999 incoming
drwx--x--x   2 adm      staff       1024 Nov 11  1999 marker
drwxrwxr-x   2 adm      gueftp      2048 Nov 10  1999 test
226 Transfer complete.
remote: -l
570 bytes received in 0.093 seconds (6.02 Kbytes/s)
ftp>

mdir
remote-files local-file -- Like dir, except multiple remote files may be specified. If interactive prompting is on, ftp will prompt the user to verify that the last argument is indeed the target local file for receiving mdir output.

mls
remote-files local-file -- Like ls, except multiple remote files may be specified. If interactive prompting is on, ftp will prompt the user to verify that the last argument is indeed the target local file for receiving mls output.

mkdir
directory-name -- Make a directory on the remote machine.

Local (Client side) FTP commands:

lcd
[ directory ] -- Change the working directory on the local machine. If no directory is specified, the user's home directory is used.

Note that new local directories can be created with

!mkdir directory and listed with !ls or !dir.

The ! can in general be used to force commands to work on the local side rather than the server side, it forces a local shell to be created.


next up previous
Next: FTP wildcards Up: Simple FTP Client Sessions Previous: Setting File Transmission Type
Dave Marshall
9/28/2001