Webserver Notes...
Own Webserver
Apache win32
Apache Config
Perl win32
MySQL win32
win32 Web Setup
Upload Utility
FTP from DOS
Next section...
Website Design
In this Page...
You will need...
Connection
Navigation
Remote Loc.
Local Loc.
File Listing
Change Remote Dir
FTP Environment
FTP Help
FTP Options
On-site File Admin
Deleting Files
Deleting Many Files
Renaming Files
Create/Remove Dir
Uploading
Binary Vs Ascii
Downloading

Webserver Notes

Using Manual FTP Under DOS

Details on the following FTP commands can be found within this document by clicking on the appropriate command here...
ftp · quit · pwd · lcd · ls · cd · help · prompt · hash · verbose · delete · mdelete · rename · mkdir · rmdir · put · mput · type · binary · ascii · get · mget

Overview

FTP - File Transfer Protocol is a means to get files from one computer to another across the internet. It is often the simplest way get the files onto the website servers.

There is a lot of software out there that allows a 'visual' FTP, usually there are two panes or windows on view; one for the files on your PC, the other for the remote file system, files are simply drag-dropped between the two. The software takes care of the details.

All well and good, but what happens when you don't have this software available to you?

Then you must resort to doing the job manually, a daunting task for the uninitiated but in reality very simple and requiring nothing more than a connection to the outside World and the DOS prompt.

FTP is a very simple unix based utility. It only has a handful of commands so there really isn't much to learn and very little scope for error as long as you understand what you are doing.

Before you begin...

Before you start you will need the following:

Making the Connection

Type the following commands into the DOS window...
(Note: The command prompt is shown in green, you type the commands in light blue, and the yellow text is what is displayed to you.)

Change to the directory with your website files...

c:\windows> cd c:\mywebsite

You are now ready to make an FTP connection type the following command and note the the domain name is prefixed with FTP and not WWW. This tells the remote machine that you want to connect to the FTP port and not the webserver or other services.

c:\mywebsite> ftp ftp.mywebsite.org.uk
Connected to ftp.mywebsite.org.uk.
220-=(<*>)=-.:. (( Welcome to PureFTPd 1.0.12 )) .:.-=(<*>)=-
220-You are user number 3 of 50 allowed.
220-Local time is now 16:35 and the load is 0.26. Server port: 21.
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
User (ftp.mywebsite.org.uk:(none)): hostusername

Once a connection has been established you will be prompted for your username and password, enter these and when they are verified you will be in. The FTP program will usually return some information, this varies between systems but should be broadly similar to what you see here.

331 User hostusername OK. Password required
Password: *******
230-User hostusername has group access to: hostusername
230 OK. Current restricted directory is /
ftp>

OK, that's how you get in, to get out is really simple, just type quit to close the FTP connection, and exit to close the DOS window.

ftp> quit
221-Goodbye. You uploaded 1234 and downloaded 5678 kbytes.
221 Logout - CPU time spent: 0.006 seconds.
c:\mywebsite> exit
 

...and you are done.
Note! If you are using a dial-up modem you will need to disconnect it as it will not happen automatically.

Locations and Navigation

By the very nature of the operation the FTP program involves two locations, the directory/files on your PC (the local machine/filesystem/server) and the target directory on the web hosting server (the remote machine/file-system/server).

You too need to be aware of where both ends of your connection are, this is probably the most serious mistake you can make in FTP, putting the files into the wrong directory on the remote server.

NOTE! FTP is a unix program and as such uses unix conventions such as forward-slashes instead of back-slashes to separate directory names and various unix derived commands and methods.

Finding Your Remote Location

To find out where you are on the remote server type pwd (Path to Working Directory) at the FTP prompt...

ftp> pwd
257 "/" is your current location
ftp>

/ is the top level directory (AKA 'root'), the direct unix equivalent to writing c:\

Finding Your Local Location

To find out where you are on the local machine use the lcd command, (LOCAL Change Directory). If you give it a directory as well it will change the underlying directory on your PC, but without it it will simply report the current directory that your PC is 'in'.

ftp> lcd
Local directory now c:\mywebsite
ftp>

Listing The Files

The next thing to do is to see what is there on the remote server, do this by entering the command ls (This is the LiSt command in unix, equivalent to dir in DOS)

ftp> ls
200 PORT command successful
150 Connecting to port 1413
publcode
tmp
www
226 3 matches total
ftp: 46 bytes received in 0.05Seconds 0.92Kbytes/sec.
ftp>

The ls command can be improved on by adding some arguments, ls -l will give a 'long' listing with a lot more information, ls -t will order each item by its timestamp and ls -r will reverse the time order so the most recent entries are at the bottom which is handy in a big directory where the listing goes off the screen.
These commands can be linked together as ls -ltr, thus:

ftp> ls -latr
200 PORT command successful
150 Connecting to port 1414
lrwxrwxrwx   1 32027  hostusername    11 Mar 26 15:29 www -> publcode
drwx------   6 32027  hostusername  4096 Mar 26 15:29 tmp
-rw-r--r--   1 32027  hostusername     9 Mar 27 02:42 .lastlogin
drwxr-x---  11 32027  99            4096 Apr 19 18:40 publcode
226-Options: -a -l -r -t
226 4 matches total
ftp: 1278 bytes received in 0.05Seconds 25.56Kbytes/sec.
ftp>

Note the extreme left hand character on each line above, if it is a 'd' then the item is a directory.

On most webservers the directory to which you go when FTP'ing is not the directory in which the website files are stored, this is usually a sub-directory. In this case the files are in the 'publcode' sub-directory, although the name of this and the path vary between systems. This is the directory offset that I referred to previously.
Anyway, we need to be in that directory so we must change directories.
This is easily done using the cd (Change Directory) command followed by the name of the directory we want to go to...

Changing the Remote Directory

ftp> cd publcode/cgi-bin
250 OK. Current directory is /publcode/cgi-bin
ftp>

Say that we wish to transfer files to the cgi-bin directory. We have pointed the remote machine at the required directory , now we have to do the same on the local machine, so...

ftp> lcd cgi-bin
Local directory now c:\mywebsite\cgi-bin
ftp>

OK, so far so good, we know know how to make an FTP connection, navigate between directories and view the contents of each directory, we are now ready to set the FTP environment and start transferring and manipulating the files.

Setting the FTP Environment

FTP is very simple to use, however it is not particularly 'verbose' and has quite a number of safeguards built in. Sometimes this can be useful, at others it can be a nuisance. By making a few simple changes you can control how FTP works for you...

Getting Help With FTP

The most useful FTP command is help! Type that at the FTP command line and a list of all possible commands will appear.

ftp> help
Commands may be abbreviated. Commands are:

!          delete       literal  prompt       send
?          debug        ls       put          status
append     dir          mdelete  pwd          trace
ascii      disconnect   mdir     quit         type
bell       get          mget     quote        user
binary     glob         mkdir    recv         verbose
bye        hash         mls      remotehelp
cd         help         mput     rename
close      lcd          open     rmdir
ftp>

Type help followed by a command and some basic information about that particular command will appear. This is an extremely useful feature, especially when you cannot remember the exact syntax for a command.

ftp> help prompt
prompt           Force interactive prompting on multiple commands
ftp>

Interactive Options

There are a few environment settings that are worth knowing about as they will make your task more user friendly...

Every single operation under FTP will be queried, you will be asked to confirm every selection. Whilst this is a useful safeguard it can be a nuisance when you have a lot of files to upload or change so turn this behaviour on and off to suit yourself.
This is done simply by typing prompt at the FTP command line.
This will toggle it between on and off, on most systems it is ON by default.
If it is on it will ask you to confirm each operation by pressing 'Y' or 'N' accordingly.

ftp> prompt
Interactive mode Off .
ftp> prompt
Interactive mode On .
ftp>

When a file is being uploaded the screen will not show anything until the operation is complete. Obviously large files will take a bit longer and the length of time for which the screen is 'dead' increases. This can be a bit disconcerting as this is exactly what happens if your connection gets broken and the whole thing fails. You have no way to tell, what you need is a progress indicator, like the 'little blue-bar' seen in so many Window's applications.

Fortunately FTP has such a facility, type hash at the FTP command line and this option is toggled on or off (just like prompt).
During the upload operation a line of hashes will slowly appear as the file gradually uploads, making it clear that the process is continuing OK.

ftp> hash
Hash mark printing On ftp: (2048 bytes/hash mark) .
ftp> hash
Hash mark printing Off .
ftp>

Another similar command is verbose. This controls how much info FTP gives you, turn it off and FTP goes very quiet and does not confirm every option back to you.

Right, now at last you know everything that is important for now and we are ready to do something with the files...

Administering Files On-site

File operations fall into three basic categories; Upload, Download and Admin.
Let's deal with the admin first...

There are only really two important operations here, deletion and renaming of files (and directories), both are pretty simple...
It is assumed that you have turned the prompting off, all commands will be executed immediately...

Deleting Single Files

To delete a file simply type the command delete followed by the name of the file you wish to delete.

ftp> delete notwanted.html
250 Deleted notwanted.html
ftp>

Deleting More Than One File

It is possible to delete more than one file at a time using the mdelete command (Multi Delete). A '*' can be used as a wildcard to match several filenames, for example...

ftp> mdelete *.html
200 TYPE is now ASCII
250 Deleted notwanted.html
250 Deleted another.html
250 Deleted something_you_wanted.html
ftp>

Note the last line above, be very careful with this option!!
Note also that the '*' wild character will not be accepted by the delete command, only mdelete.

'TYPE is now ASCII' is important and will be explained in the section about uploading files.

Renaming Files

Renaming files is very simple, use the rename command, followed by the filename that you want to change and then the new name.
Thus...

ftp> rename oldname.html newname.html
350 RNFR accepted - file exists, ready for destination
250 File successfully renamed or moved
ftp>

NOTE! To move a file simply rename it to the new location, on unix systems there is no distinction between 'rename' and 'move'.

Creating/Removing Directories On-site

Directories are just as easy to maintain as files.

Create directories using the mkdir (Make Directory) and delete them using the rmdir (Remove Directory) command.

ftp> mkdir demo
257 "demo" : The directory was successfully created
ftp>
ftp> rmdir demo
250 The directory was successfully removed
ftp>

NOTE! Before you can remove a directory it must be empty, you must first get rid of all the files and subdirectories within it.

Uploading Files

To upload a file is to copy it from your PC, the local system, to the server, the remote system.

This is a fairly simple operation but it is imperative that you have both the local and remote directories set correctly else the file will not go where you expect it to.

Uploading is achieved using the put command at the FTP prompt followed by the filename.

ftp> put myfile.html
200 PORT command successful
150 Connecting to port 1633
226-97892.9 Mbytes free disk space
226-File successfully transferred
226 0.344 seconds (measured here), 1.24 Kbytes per second
ftp: 436 bytes sent in 0.00Seconds 436000.00Kbytes/sec.
ftp>

In the above example the FTP program will look for myfile.html within whichever directory lcd is set to on your PC and will place it in whichever directory pwd is set to on the remote machine.

You can also specify a sub directory on your PC to take the files from without having to change the local directory, thus...

ftp> put subdir/myfile.html
...
ftp: 436 bytes sent in 0.00Seconds 436000.00Kbytes/sec.
ftp>

In the above example the FTP program will look for myfile.html within the subdirectory of lcd called 'subdir'.

There is an additional variant of the put command called mput. Like mdelete this works on multiple files, use it as follows and in conjuntion with prompt and hash to keep the output quick and simple...

ftp> mput *.html

In this example the FTP program will upload every .html file from the lcd directory on your PC to the pwd directory on the remote server.

The Binary Vs Ascii Gotcha!

There is one 'tricksy' setting in FTP. By default all files are transferred as text files. This is fine for text or html but if you try to upload an image file , ie .jpg or .gif or a Word document etc then the end result will be a mangled mess.

I am not going to go into the details of why this is so, merely to explain what you must do to avoid this problem.

The default text mode is called 'ascii'. To upload other types of files you must set the file type to 'binary'. Now when you upload images etc the files will be correctly parsed and stored.

To find the current file type simply type type at the FTP command line and the file transfer type will be reported to you.

To set it to binary simply type binary at the FTP prompt.

To set it to ascii simply type ascii at the FTP prompt,
thus...

ftp> type
Using ascii mode to transfer files.
ftp>
ftp> binary
200 TYPE is now 8-bit binary
ftp>
ftp> type
Using binary mode to transfer files.
ftp>
ftp> ascii
200 TYPE is now ASCII
ftp>
ftp> type
Using ascii mode to transfer files.
ftp>

Downloading Files

A familiar term, to download is to copy a file from a remote machine to a local one, ie your PC.

This is uses the get FTP command which is essentially identical to the put command. As before it is sensitive to the local and remote directories and the file type needs to be set correctly although most Window's PC s are less sensitive.

ftp> get myfile.html
200 PORT command successful
150 Connecting to port 1635
226-File successfully transferred
226 0.000 seconds (measured here), 2.74 Mbytes per second
ftp: 456 bytes received in 0.00Seconds 456000.00Kbytes/sec.
ftp>

Again like the put and mput commands this too allows multiple file downloads using the mget command.

ftp> mget *.html

Unsurprisingly the above command will copy all .html files from whichever directory you are in on the remote machine (pwd) to the current local directory on your PC as specified by lcd.

And that is it, you now know all of the FTP commands that you will need to maintain a website filesystem.

This isn't rocket science, FTP is a very simple utility, once you have done this a few times it becomes very easy and straightforward.

Show Style-Switcher...