Programmers use a variety of tools/utility programs, some of which we have looked at already: editors, compilers, debuggers etc. This lecture looks at some tools that aren't directly related to programming, but form a useful part of a programmers toolkit.
Ever since two computers have been connected and talking to each other the direct transfer of a file from one computer to another has been an area of research. Computers store information in files, therefore when transferring information from one computer to another it is usually equivalent to transferring a file. Hence, files are the basic unit of transfer, even though files can be of vastly different sizes.
The introduction and boom in the use of modems dramatically increased the number of computers connected together.
Initially, modems where designed for simply transferring ASCII text characters between computers. Many ASCII control characters (from 1->27) are used by the modems in controlling the communication link with each other, hence these characters get caught by the modem and do not generally get through from computer to computer. Unfortunately, many files use these same characters as part of their data, for example program executable and graphic files.
So protocols have been established that allow all characters of a file to be transferred easily from computer-to-computer through a modem. Some of these protocols have been:
The subjects Computer Networks and Data Communications cover communications in (far) more detail.
There are three main types of programs that use ftp:
Ws_ftp is available on the PC Network. It is useful for transferring files to/from the Unix systems at Uni. If you want to transfer your work from Unix to the PC Network this can be done by ftping the files to a PC.
ftp is the name of a program provided with most computers, including Windows and Unix systems. Generally you make a connection between your computer to another computer (the host). Naturally, you require an account on the host computer.
In Windows you can start the ftp program from the Start > Run... window simply by entering the command:
ftp hostname.location
e.g.:
ftp redgum.bendigo.latrobe.edu.au
To connect to redgum you will then need to enter your username and password. The current directory on the redgum will be your home directory.
You can also use the ftp 'open' command to create a connection to another computer from within a ftp program. e.g.
ftp
open redgum.bendigo.latrobe.edu.au
The ftp program is also installed as part of the Unix system, so can be run from
any Unix computer:
ftp hostname.location
There are two main file transfer modes:
1. Binary (or Image) - the file is copied byte-by-byte. Use this mode when
transferring programs and graphic files
2. ASCII - End-Of-Lines are converted from one system to the EOLN
codes used in the other system.
eg: a sample text file on a PC:
Text Corresponding ASCII code stored in a file on a PC Hello out
there!72 101 108 108 111 32 111 117 116 13 10 116 104 101 114 101 33 <EOF>
The same text in Unix format only has a single character 10 to represent the end-of-line:
Text Corresponding ASCII codes in Unix Hello out
there!72 101 108 108 111 32 111 117 116 10 116 104 101 114 101 33 <EOF>
What would the ASCII codes of the same text look like on an Apple system?
Note:
The Unix programs dos2unix and unix2dos can be used to convert text files to from windows to unix formats and vice-versa. This is occasionally necessary when the ftp program does not do this correctly. Two command formats are given below, then first replaces the existing file with the new file. The second format writes it to a new file (safer). Don't use wildcards with the -n option.
Format
dos2unix file-name dos2unix -n windows-file-name unix-file-name unix2dos file-name unix2dos -n unix-file-name windows-file-name
Examples
dos2unix HelloWorld.java mv HelloWorld.java HelloWorldWin.java dos2unix -n HelloWorldWin.java HelloWorld.java unix2dos HelloWorld.java unix2dos -n HelloWorldUnix.java HelloWorld.java
A standard set of ftp commands have been specified. Some useful ones are:
| Command | Examples | Description |
|---|---|---|
| ? | ? | Display a list of commands with brief descriptions. This is equivalent to the help command. |
| ? command | ? ls | Display help on the named command |
| open | open redgum.bendigo.latrobe.edu.au | Open a connection to a host |
| ls | ls | List files on the ftp server |
| cd | cd cd /pub/ |
Change directory on the ftp server |
| lcd | lcd | Show and change directory on the local computer (your computer) |
| ascii | ascii | Set transfer mode to ASCII. Used for text files such as source code files |
| binary | binary | Set transfer mode to binary. Used for binary files such as graphics files |
| put | put Add.java put photo01.jpg |
Send (upload) a file from your computer to the ftp server |
| mput pattern | mput *.java mput Add* |
Send (upload) multiple files from your computer to the ftp server |
| get | get Add.java | Get (download) a file from the ftp server to your computer |
| mget pattern | mget *.jpg mget photo* |
Get (download) multiple file from the ftp server to your computer |
| close | Close the connection | |
| bye | Close the connection and exit ftp |
There are also many commands that allow your to perform remote file maintenance: mkdir, rmdir, rename and delete.
Note these will have no effect on anonymous connections.
More sophisticated command line ftp programs are available.
Once the Internet starting expanding many servers created directories especially for general ftp use. They all had the user name 'anonymous' and the password is usually your email address. You do not need an account on the computer for anonymous ftp.
An example of a site that allows anonymous ftp is Aarnet: http://mirror.aarnet.edu.au/
Everything is laid out for you graphically. eg: ws_ftp
To run ws_ftp on the PC Network, select Start > Program > WS_FTP > WS_FTP95 LE.
If the following screen isn't displayed, click the Connect button.
Click the New button and fill in the following information:
Host Name/Address: redgum or redgum.bendigo.latrobe.edu.au
User ID: your Unix username
You will be prompted for your Unix password.
Normally you would select redgum from the Profile Name: combobox next time you wanted to connect to redgum, unfortunately PCs on the PC network don't remember changes to ftp settings. So you will need to retype the settings next time.
For anonymous ftp: specify the Host Name/Address, input anonymous for the User ID, check (tick) the anonymous checkbox and click the Ok button.
The ws_ftp screen below has the local directory/files on the left and the connected
system (remote server) on the right.
Simply press the arrows in the middle to transfer files from one computer to another.
Change directories, disk drives etc much as you would in Windows. Note the ASCII/Binary
selection radio buttons.
Simple. Open a connection to a directory or an actual file for downloading specifying the ftp protocol.
Once a directory is opened it is very easy to navigate around.
Restriction: Can only download files using this method.
Note: Many WWW Page Authoring applications have a Publish (upload) facility.
Winzip is a compression program available for PCs. It is used to zip multiple files into one file, generally saving space. The amount of file compression depends on the data in the files being compressed, for example text files sometimes compress to one-tenth of the original size whereas executable files usually don't compress much at all. Single or multiple files can be extracted from the zip file. An advantage of zip when backing up files is that it preserves the modified date when zipping and extracting files (unlike copy).
Given limited storage space, zipping files is a good way to save space e.g. on the PC Network, floppies etc.
To run Winzip on the PC Network, select: Start > Programs > WinZip > WinZip
If you a saving a few files only
If you want to save whole directories (and subdirectories)
The Winzip window, has columns for the file Size (showing the file size before compression) and Packed (size of the file after compression).
The uncompressed size of the all of the files is displayed in the status bar at the bottom of the window (e.g. Total 158 files, 1,644KB). The size of the zip file after compression is shown by selecting File > Properties... (e.g. File size: 217237 (bytes)).
Files can be added to a zip file by opening the zip file, click the Add button and selecting the files to add to the zip file, the click the Add button.
To run winzip and open a zip (archive) file, either:
Select the files to be extracted and click the Extract button.
Specify the folder/directory the files are to be extracted to, and click the Extract button.
Zip files created on PCs should be able to be unzipped on Unix and vice-versa.
zip/unzip are command line compression commands available on Unix.
Format
zip [-hrT] zip-file-name files-to-zip
Examples
Zips all of the files in the current directory into the file mywork.zip
zip mywork *
Zips all of the files in the current directory and all its subdirectories into the file allmywork.zip
zip -r allmywork.zip *
Zips the files: tut01.java tut02.java story.txt into the zip file someofmywork.zip
zip someofmywork tut01.java tut02.java story.txt
Zips all of the files in the ProgEnv directory and all od its subdirectories into the zip file progEnvBackup.zip
zip -r progEnvBackup.zip ProgEnv/*
Help on the zip command
zip -h
Check the zip file for integrity
zip -T mywork
The unzip command unzips a zip file, extracting the files into the current directory. If the zip file contains subdirectories these will be automatically created and files put in them if necessary.
Format
unzip [-l] zipfilename [-d directoryname]
Examples
Unzips all of the files in the zip file mywork.zip into the current directory. If the zip file contains subdirectories these will be automatically created if necessary.
unzip mywork
Unzips all of the files in the zip file progEnvBackup.zip into the directory ProgEnv. If the zip file contains subdirectories these will be automatically created if necessary.
unzip progEnvBackup -d ProgEnv
List all of the files in the zip file mywork.zip (but doesn't unzip them) displaying them a page at a time by piping to less
unzip -l mywork.zip | less
ssh (secure shell) is a secure way of logging onto another machine, using an encrypted connection. You can remotely log onto Unix using ssh. This can be done from one Unix box to another or from the PC network to Unix.
Log onto a PC and run Cygwin (Start > Cygwin > Cygwin Bash Shell)
In the Cygwin window type: ssh your-unixuser-name@computer-name.bendigo.latrobe.edu.au
e.g.
ssh tjwhitfort@redgum.bendigo.latrobe.edu.au
ssh tjwhitfort@indyg.bendigo.latrobe.edu.au
PuTTY is a useful free ssh client program (http://www.chiark.greenend.org.uk/~sgtatham/putty/)
Written by Tim Whitfort.