|
This tutorial
will show you how to easily transfer an entire directory tree without
having to do each file independently. This is easily done if you have
a fancy FTP client application. However, if you are transferring from
server to server (for example if you change web hosts) you may need
to perform a FTP transfer via command line tools. This may be especially
important if you use web site scripts which require specific permissions.
|
|
BACKGROUND: |
What is FTP? |
The File
Transfer Protocol (FTP) is a common tool used to copy files between
computers on the Internet. Note that it copies files rather than moving
files (it will not alter the original file). If you plan on using FTP
to transfer
files from one server to another (old host to your new host), then you
must be able to log into both servers.
Your old
server is where you will do your prep work and is where you will issue
the FTP command - this server is called the "local host".
Your new server is called the "remote host".
The purpose behind creating this tutorial is because some sites has many
scripts and directories that require specific permissions to function
correctly. It would take a long time to reconfigure the scripts
on a new server. But this method saves hours of work. All you do is zip the directory, ftp the zip file to the new site
and unzip the file - your done. All the permissions remain intact. You
may need to change some path pointers in your scripts but that is minor
compared to checking the permissions of each file.
|
|
STEP 1: |
Log
into the server containing your file(s) to be transferred. |
- First,
you must
telnet
or SSH into your old host server containing your web site
(contact your host if you don't have access).
- Once you
log in, use the change directory command "cd"
to navigate to the directory just outside of your public html directory
(or whatever directory you want to transfer). For example, if you store
your web site in /home/user/public_html then you would change directory
to the /home/user directory. To view which directory you currently reside
in, use the "pwd" command. To view the contents
of your directory, use the "ls" or "ls
-lsa" command.
|
|
STEP 2: |
Use
the "tar" command to create a archive of your directory structure. |
- The "tar"
command stands for "tape archive". What it can do
is archive an entire directory into a single file. This is great for
backup and transfer purposes.
- Illustrated
below is an example using the "pwd" command
to determine the working directory (yours will be different) and the
"ls" command to list the contents of the
directory.

- In this
example, the directory "public_html" contains my web site
and cgi-bin directory where all my scripts are located. Therefore, I
want to create a tape archive of the entire public_html directory.
- Type "tar
-cvf anyname.tar dirname" to create
an archive of your directory. In our example, I would type "tar
-cvf webarchive.tar public_html". The dirname
has to be the name of the directory you want to tar but the resulting
tar file (anyname.tar) can be any name.
- Illustrated
below is an example using the tar command. You will notice that it listed
all the files and directories that it archived. Running a "ls"
command shows that a new "webarchive.tar" file has been created
while the original public_html directory remains. <NOTE:
the tar command creates a copy of the original directory - it
does not move or delete the directory or files contained therein.>
|
|
STEP 3: |
Use
the gzip command to compress the archive file you just created. |
- The "gzip"
command is the UNIX flavor of WinZIP. It is used to compress large files
into a more manageable size. A smaller file size will result in a quicker
FTP transfer.
- Type "gzip
anyname.tar" to compress your archive. In our
example, I would type "gzip webarchive.tar".
Illustrated below is an example of the gzip command followed by a listing
of the directory. You will note the that gzip command appends a ".gz"
suffix to the end of the file.
|
|
STEP 4: |
Transfer
the file to your new host or backup server. |
- There
are many tutorials available on the web for using command line FTP (just
do a search for "command line FTP" on Google). Here I will
present just the basics.
- Assuming
that you are still logged into your old server (localhost), type "ftp
www.yournewserver.com". The remotehost should be prompt
your for your username and password similar to the screenshot below.

- Once you
have successfully logged in, then type "put anyname.tar.gz".
In our example, I would type "put webarchive.tar.gz".
The screen shot below illustrates a successful transfer.

- Type "quit"
when the transfer is complete. You should end up back at your shell
command prompt prior to initiating the ftp session (illustrated below).

|
|
STEP 5: |
Log
into the new server where you transferred your archive file and move your
archive to the appropriate directory. |
- Log into
your new server using
telnet
or SSH (contact your host if you don't have access).
- Once you
log in, use the change directory command "cd"
to navigate to the directory containing your uploaded archive. It will
probably be located in your home directory. Remember the "pwd"
command will show you where you are currently located in the directory
tree.
- Using
the move command "mv" move the file to the
directory where you wish to expand the archive (this
should be the root directory of your web site - if your web site is
published in the "/home/user/www" directory, you should be
in "/home/user/".)
- Then use
the "cd" command to change your directory
to the location where you just moved the archive. Illustrated below
is an example on my server (inside the "test" directory contains
my "www" directory where my site is published).
|
|
STEP 6: |
Unzip
and untar your archive. |
- Use the
"gunzip" command to unzip your archive (i.e., "gunzip
anyname.tar.gz"). In our example I would type
"gunzip webarchive.tar.gz".
- Next,
use the "tar" command to unextract your archive
(i.e., "tar -xvf anyname.tar). In our
example I would type "tar -xvf webarchive.tar".
Illustrated below is an example of these commands followed by a list
directory command, "ls".
|
|
STEP 7: |
If
necessary, move your unzipped data to the appropriate directory. |
- In our
example the root web publishing directory is different between our new
and old server. On our old server the directory was "public_html"
and on the new server it is "www". Therefore, we need to copy
data from "public_html" to "www". If your root web
publishing directories are the same between the two servers, then you
may skip this step.
- Use the
copy command "cp -rv public_html/* www"
to copy data from your archive into your root web folder. Illustrated
below is an example of the command being issued where "public_html"
is the old directory and "www" is the new.

- If you
have similar files in the new directory, you may be prompted to overwrite
them. If you are unsure whether or not it is safe to overwrite certain
files, I would suggest that you do not overwrite the files and contact
your web host provider. Ask them exactly which files are required in
the root web publishing directory and which are safe to overwrite.
|
|
STEP 8: |
Testing
your transfer. |
- That should
complete the transfer. Test your new site by using your IP address or
appropriate means as defined by your new hosting provider. If your home
page doesn't show up, be certain that you transferred the files to the
appropriate directory. Remember the "pwd"
command will show you which directory you are currently in.
- Once you
have successfully tested your transfer, you may delete your *.tar file
to save space. Use the "rm *.tar" command
to delete the file while logged in via telnet or SSH.
|
|
References |
Links
of interest. |
|
|
|
|