ITEM: H0310L

I need to automate FTP transfers.


Question:

I am trying automate an FTP file transfer.  Eventually I would like 
to be able to run it with a cron job.   I have been experimenting with 
FTP macros but when I try to run them, I get the following error:

        "macro definition missing null line terminator"
        "221 service closing connection."

Response:

FTP macros group together ftp subcommands to make a new subcommand.  
To create an ftp macro, you will need to have a .netrc file in the home
directory of the user that wants to run it.  

For example, if I want to write a macro that will copy the /etc/motd file
from a remote computer called 'vwbus' and put it into a directory called  
'/home/hippy/cosmic/stuff' on my local system, I would create a .netrc file 
in my home directory that looks like this:

   machine vwbus                                          \<- 
   macdef getmotd                                           | 
   lcd /home/hippy/cosmic/stuff                             |  Example .netrc
   cd /etc                                                  |
   get motd                                                 |
                                                            |
                                                          \<-
   
(Note: If you have more than one machine in your .netrc file, the macro
will be define only on the machine listed immediately above the macro.
To add more than one macro for any one machine, simply separate the macros
by a blank line.)
                                                  
To use this macro, I would type, 

   ftp vwbus

The RISC will respond with something like this:

   Connected to vwbus 
   220 vwbus FTP server (Version 4.7 Tue Mar 09 17:39:34 CST 1993) ready.   
   Name (vwbus:hippy):

After you type in your name and password for the remote system, you will get 
an ftp prompt like this:

   ftp>

To run the macro type, '$getmotd' at the prompt.  

The result will look something like this:

lcd /home/hippy/cosmic/stuff
Local directory now /home/hippy/cosmic/stuff
cd /etc
250 CWD command successful.
get motd
200 PORT command successful.
150 Opening data connection for motd (1602 bytes).
226 Transfer complete.
1624 bytes received in 0.096 seconds (16.52 Kbytes/s)
ftp> 

This new subcommand or macro must still be executed at the ftp 
prompt.  To do FTP file transfer from a script, with out the need 
to be interactive, you could put the login name and password in the 
.netrc file, and use a 'here' document to start the macro.

Your new .netrc file would look like this:

   machine vwbus login hippy password moonbeam            \<- 
   macdef getmotd                                           | 
   lcd /home/hippy/cosmic/stuff                             |  Example .netrc
   cd /etc                                                  |
   get motd                                                 |
                                                            |
                                                         \<-
and a sample script would be:

   ftp vwbus \<\
Support Line: I need to automate FTP transfers. ITEM: H0310L
Dated: March 1994 Category: N/A
This HTML file was generated 99/06/24~13:30:48
Comments or suggestions? Contact us