Please contact or Mt Xia for assistance with all your shell programming needs.

  • 8. ADVANCED FEATURES OF FTP. Go to the bottom, first,previous,next, last section, table of contents.


    This chapter will discuss some advanced features of the FTP server as implemented on the Multimax. The introduction of FTP in UNIX for Beginning Users gave an elementary introduction to some of the features. If you are not familiar with the basics, please refer to that manual. It is not the purpose to review those basics here. The FTP (Internet file transfer program) is the user interface to the DARPA File Transfer Protocol. This utility program will transfer files to and from a remote computer. In order for files to be transferred from the local computer to a remote computer, a connection must be established. This can be done from the FTP command line. The connection to the remote computer will remain active until it is terminated by the user. The remote computer with whom the connection is to be made can be specified on the FTP command. In this case, FTP will immediately try to establish a connection. If the remote computer is not specified, FTP will enter its command interpreter mode and wait for instructions; a prompt will be displayed. FTP does have a help feature, and all 58 commands can be listed. It will also give a terse description of each command. In addition, there are on-line manual pages which can be accessed by using the man command in UMAX.

    8.1 Initializing FTP on UMAX

    The term, "local computer," will refer to the Multimax. The "remote computer" will refer to the other computer with which you are trying to send/receive files. For purposes of this course, we will be referring to the VAX minicomputer as the remote computer. Please be aware that these procedures will work for any computer connected to Ethernet and having an FTP server. FTP can be invoked on the local computer using the following syntax:
      Command Format:  ftp [-v] [-d] [-i] [-n] [-g] [host]         
             -v = verbose on, forces ftp to show all responses     
                  from the remote server                           
             -d = enables debugging                                
             -i = turn off interactive prompting during            
                  multiple file transfers.                         
             -n = disables the "auto-login" feature                
             -g = disable filename globbing                        
             host = the name of the remote computer                
    NOTE: UMAX (UNIX) is case sensitive. The commands and options must be entered as shown.

    8.2 Multiple File Transfers

    The syntax for the multiple get command is:
      Command Format:  mget remote-files                           
      remote-files = remote computer wildcard specification        
                     file1 file2 ... filen                        
    The remote computer wildcard specification is expanded in a process called globbing. Once the globbing is complete, a get is performed on each filename; and it is transferred to the local computer. The filename is the same on both computers. You can specify the filenames to be transferred separating them with spaces. Example: ftp>mget *.dat;* This command will transfer all versions of the remote-files that have the filename extension of .dat. If the option -i was specified on the call to FTP, then the files will be transferred automatically. If the option was not specified, FTP will prompt you before transferring each file. Sample Session: ftp>mget *.dat mget change_pass.dat;1? The default is 'yes', pressing (Ret) will cause the file to be sent to the local directory. If you don't want this file transferred, enter n(Ret); you will then be prompted for the next file, if one exists.

    8.3 Auto Login Feature

    It is possible to have the login procedure occur automatically. To do this requires a file in your home directory called .netrc. The .netrc file contains login and initialization information to be used by the auto-login process. The following variables are used and can be separated by spaces, tabs, or new lines. machine name This is the name of the remote computer. The auto-login process will search the .netrc file for a machine variable that matches the name of the remote computer on the ftp command or as an open command argument. Once a match is found, the next variables are also processed until the end of file or another machine variable is encountered. login name This is the username on the remote system. If this variable is present, the auto-login process will login to the remote computer with the given username. password string This is the password to be used when logging in to the remote system. NOTE: If this variable is present in the .netrc file, ftp will abort the auto-login process if the .netrc file is readable by anyone but the user. account string This supplies an additional account password. If present, the auto-login process will supply the string as an additional password if required by the remote server. macdef name This defines a macro. This variable will function like the ftp macdef command. A macro is defined with the specified name, its contents begin with the next .netrc line and continue until a null line (2 new line characters). If a macro named init is defined, it will be executed as the last step of the auto-login process. Sample Session: $cat .netrc machine erc830 login teacher password secret1 machine erc780 login rharding password secret2 $ To invoke the auto-login feature, type the ftp command and enter the name of the remote computer as an argument. Sample Session: $ftp erc830 Connected to erc830. 220 erc830 Wollongong FTP Server (Ver 5.0) at Tue Oct 23 331 Password required for rharding. 230 User logged in, default directory D_1131:[RHARDING] ftp> If the .netrc file is readable by anyone other than the user, the following error message will appear; and the connection will not be made to the remote computer. Sample Session: $ls -l .netrc $ftp erc830 Connected to erc830. 220 erc830 Wollongong FTP Server (Ver 5.0) at Tue Oct 23 Error - .netrc file not correct mode. Remove password or correct code. 221 Goodbye. ftp> To correct this error, change the mode of the .netrc file so it is not readable by other users or remove the password from the file. This is to prevent your password from being read by an unauthorized user.

    8.4 Macros

    Macros are a single instruction that a program replaces by several, usually, more complex instructions. The ftp command to create a macro definition is:
      Command Format:  macdef macro-name                           
      macro-name - the name of the macro                           
    After the macdef command is given, all subsequent lines are stored as a macro with the name macro_def. Consecutive newline characters or carriage returns terminate the input mode into the macro. There is a limit of 16 defined macros and a limit of 4096 characters in all defined macros. Sample Session: ftp>macdef get_files open erc780 get file_1 put result_2 close ftp> In this example, the four lines of the macro can be executed simply be entering get_files at the ftp prompt. The macro will only exist until the current ftp session is closed.

    8.5 Filename Translation

    Filename conventions differ from one computer to another, and FTP will allow you to translate the name as it is transferred. One way is to specify the name of the file as it is to exist on the local computer. This is done by the argument on the put or get command.
      Command Format:  put local-file [remote-file]                
                       get remote-file [local-file]                
    If you don't specify the remote-file (for the put command) or the local-file (for the get command), the name will be the same on both the local and remote computer. This can cause a problem if you are not aware of it. There is an FTP command that will allow the name to be translated automatically.
      Command Format:  nmap [inpattern outpattern]                 
    If no arguments are supplied, it will set or unset the filename mapping mechanism. If arguments are specified, remote filenames are mapped during mput (multiple file puts) and put (single file) commands that are issued without a specified remote filename. If arguments are specified, local filenames are mapped during mget (multiple file gets) and get (single file) commands that are issued without a specified local filename. The mapping follows the pattern set by inpattern and outpattern. Variable templating is done by including the sequences "$1", "$2",...."$9 "in inpattern. All other characters are treated literally and are used to determine the nmap inpattern variable values. For example, say the inpattern was $1.$2 and the remote filename is, $1 would have the value mydata and $2 would have the value data. The outpattern determines the resulting mapped filename. The sequences "$1", "$2",..."$9", are replaced by the value resulting from the inpattern template. "$0" is replaced by the original filename.

    8.6 Aborting Transfers

    Press the terminal interrupt key (usually Ctrl-C) to abort a file transfer. The sending transfer will stop immediately. Receiving transfers will be halted by FTP sending an ABOR command to the remote server and discarding any further data that is received. If the remote server doesn't support the ABOR protocol command the ftp> prompt will not appear until the requested file has been sent.

    8.7 More Remote Computer Commands

    These commands can be useful when working with the directories on the remote computer.
      Command Format:  cdup                                        
    This FTP command will change the remote machine current working directory to the parent of the current working directory.
     Command Format:  delete remote-file                          
      remote-file  name of the file to delete                      
    This FTP command will delete the specified file.
      Command Format:  mdelete [remote-files]                      
      remote-files  names of the files to delete                   
    This FTP command acts as a multiple delete. It will delete all the specified files.
      Command Format:  mkdir directory-name                        
      directory-name  the name of the directory to be created      
                      on the remote computer.                      
    This FTP command will create a directory on the remote computer.
      Command Format:  rmdir directory-name                        
      directory-name  the name of the directory on the remote      
                      computer that will be removed.               
    This FTP command will remove the specified directory. NOTE: This command will not work with some remote servers.

    Workshop 8

    This workshop will reinforce your understanding of the ideas presented in Chapter 9. Login to the Multimax using the username and password given to you by the instructor. Each student is to complete the entire workshop. DESK EXERCISES (10 minutes) 1. What FTP command is used to transfer more than one file at a time? What FTP command will give a prompt to you before each file is retrieved? Suggestion: there are two ways 2. What is the name of the file where the auto-login variables are found? Extra credit: Why does this file begin with a dot (.)? 3. How can the file in question the auto-login file be protected from unauthorized reading? 4. What do the following FTP commands do? cdup delete (tough question) mdelete (ditto) mkdir rmdir COMPUTER EXERCISES (30 minutes) 5. Transfer all the files from on the VAX (erc830) to the domax1. Use only one command and use wildcards. The username and password for the VAX will be given to you by the instructor. 6. Transfer the files from the VAX and this time translate the names of the files as they are transferred. 7. Create an auto-login file for the erc830 and then do an auto-login to the VAX. 8. Logout.

    Go to the top, first,previous,next, last section, table of contents.