The OpenNET Project / Index page

[ новости /+++ | форум | wiki | теги | ]

Поиск:  Каталог документации

FTP HOWTO

FTP (File Transfer Protocol) is a client/server tcp protocol that allows a
user to transfer files to and from a remote network site.

An FTP site is a computer that is running FTP server software.

An FTP client is the userland application that provides access to FTP
servers. There are many FTP clients available. Some are graphical, some are
text-based. 

The standard ftp program is the original ftp client. It comes standard with
most Linux distributions. It first appeared in 4.2BSD, which was developed
by the University of California, Berkeley. 

It's easy to use ftp. Let's say you want to connect to the anonymous ftp
site metalab.unc.edu, to download the latest Linux kernel source.

At the command line, type:

$ ftp metalab.unc.edu
 
The ftp program will attempt to connect to metalab.unc.edu. When it
succeeds, it will ask you for a login:

220 helios.oit.unc.edu FTP server (Version wu-2.6.0(2) Wed Nov 17 14:44:12
EST 1999) ready.
Name (metalab.unc.edu:mkb): 

We log in as anonymous or ftp, to get to the public archive.

331 Guest login ok, send your complete e-mail address as password.
Password:

We now enter a complete e-mail address as the password. After ftp has a
successful login, the following information is given to us:

Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 

Note that the file transfer type is binary. Binary mode transfers the files,
bit by bit, as they are on the FTP server. Ascii mode, however, will download
the text directly. You can type ascii or binary to switch between the types.

You want to download the kernel source, so you leave the file transfer type
at binary.

You do an ls to see a list of the files:

ftp> ls

200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
total 33590
-r--r--r--   1 root     other    34348506 Dec 03 03:53 IAFA-LISTINGS
lrwxrwxrwx   1 root     other           7 Jul 15  1997 README -> WELCOME
-rw-r--r--   1 root     other         890 Nov 15 13:11 WELCOME
dr-xr-xr-x   2 root     other         512 Jul 15  1997 bin
dr-xr-xr-x   2 root     other         512 Jul 15  1997 dev
dr-xr-xr-x   2 root     other         512 Jul 18  1997 etc
drwxrwxrwx  11 ftp      20           4608 Nov 28 16:00 incoming
lrwxrwxrwx   1 root     other          13 Jun 04  1998 ls-lR -> IAFA-LISTINGS
dr-xr-xr-x  17 root     root          512 Jun 08 11:43 pub
dr-xr-xr-x   3 root     other         512 Jul 15  1997 unc
dr-xr-xr-x   5 root     other         512 Jul 15  1997 usr
226 Transfer complete.

You know that the kernel sources are in the directory /pub/Linux/kernel, so
you type the following to get into that directory:

ftp> cd pub/Linux/kernel
250-README for kernel
250-
250-What you'll find here: kernel sources and patches
250-
250-
250 CWD command successful.

The messages you see, which begin with "250", are information messages sent
by the server. In this case, the ftp server is configured to automatically
send you the README file when you cd into the directory.

Now, after doing another ls, you see that you want to cd into the v2.2
directory. You do yet another ls, and find the file you want to download. It
is linux-2.2.13.tar.gz. So you type this:

ftp> get linux-2.2.13.tar.gz
local: linux-2.2.13.tar.gz remote: linux-2.2.13.tar.gz
200 PORT command successful.
150 Opening BINARY mode data connection for linux-2.2.13.tar.gz (15079540
bytes).

The ftp program has started saving the remote file linux-2.2.13.tar.gz as
the local file linux-2.2.13.tar.gz.

If you wanted to save it as the local file "foo.tar.gz", you could have
specified it like this:

ftp> get linux-2.2.13.tar.gz foo.tar.gz
local: foo.tar.gz remote: linux-2.2.13.tar.gz
200 PORT command successful.
150 Opening BINARY mode data connection for linux-2.2.13.tar.gz (15079540
bytes).

If you want to download more than one file at a time, you'd have to use the
mget command. You can use mget together with a space-delimited list of
filenames you want to get, or you can use wildcards with the mget command.
For example:

ftp> mget linux*

Would get all files starting with the string "linux". Normally, mget will
prompt you for each file before it downloads it. You can toggle this by
using the prompt command.


Now, wouldn't it be nice if you could watch the progress while you're
downloading a file with ftp? You can use the hash command to print out hash
marks as you download a file:

ftp> hash
Hash mark printing on (1024 bytes/hash mark).

As you can tell, ftp will print a hash mark for every 1024 bytes of data you
download.

There is also a tick option.

ftp> tick           
Tick counter printing on (10240 bytes/tick increment).

This will print something to this effect as you download a file:

Bytes transferred: 11680


Now let's say you've written a piece of software, and you want to upload it
to MetaLab to be included in their Linux software archive. First, you'd
change to the /incoming directory, then you'd use the put command:

ftp> put foo.tar.gz
local: foo.tar.gz remote: foo.tar.gz
200 PORT command successful.
150 Opening BINARY mode data connection for foo.tar.gz.
226 Transfer complete.
10257 bytes sent in 0.00316 secs (3.2e+03 Kbytes/sec)

The put command works the same way as the get command, so you can use mput
to upload multiple files at the same time. You can also upload a local file
with a different filename on the server by specifying the remote filename as
an argument.

What if the file foo.tar.gz is not in your current local directory when you
try to upload it? You can switch local directories by using the lcd command:

ftp> lcd /home/foo/
Local directory now /home/foo

The ftp client also supports using the ! to run local commands. For example,
to get a listing of files in your current local directory, do this:

ftp> !ls

The way this works is that ftp calls the local ls program to give you the
listing. You can run any local command via the ftp program simply by
prepending a "!" to it.

There are many other ftp commands. You can make a directory on the remote
server using the mkdir command. You can remove a file on the remote server
using the delete command, or rmdir to remove a directory. You can also
change file permissions using the chmod command. 

For more complete information on using ftp, please see the online help in
the ftp program (accessible by typing help with no arguments for a list of
commands, or help  for specific help on a command). You can
also read the Unix man page for ftp by typing:

$ man ftp

at your command prompt.



Enhanced FTP client programs
----------------------------

The original ftp program was the original ftp client, and it is the only ftp
client that you can be certain is available on most systems (even Win32
comes with the ftp command, albeit an archaic, braindead version of it).

Many enterprising programmers have written ftp clients that offer greater
ease of use and more advanced features such as site bookmarks, queueing of
files to download/upload, etc. There even exist some graphical FTP clients
for use with the X Window system.

NcFTP
-----

NcFTP is the all-time favorite ftp client of many Unix users. It comes
bundled with most Linux distributions, and offers many advanced features.
Version 2 of NcFTP had a curses based full-screen mode. This was done away
with in Version 3 (now in beta). 

At first glance, NcFTP seems a lot like the stock ftp client. But it has
command line tab-completion, bookmarks. It's not 100% compatible with the
commands that standard ftp uses. For example, get and put act like mget and
mput do in standard ftp. So if you want to save a remote file as a different
local filename, you'd do get -z remotename localname. Thankfully, NcFTP has
a nice online help system to assist you in learning the commands. 

You can get the latest version of NcFTP at http://www.ncftp.com



Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру