Automate FTP transfer
I have a cron job that calls a script every night. The
script is supposed to ftp a few files to a remote host. I would
like to transfer these files automatically without having to
login. How can I do this?
How to write a FTP macro
FTP (File Transfer Protocol) provides a scripting facility known
as FTP "macros". FTP macros are defined in the $HOME/.netrc file.
In order for FTP to use the $HOME/.netrc file, this file must
have read and write permission for the owner, and no other permissions.
Use the "chmod 600 $HOME/.netrc" command to set the correct
Macros have the following properties:
1 - A macro is associated with the login entry immediately preceeding
it, i.e. macros are not global to the $HOME/.netrc file.
2 - The $HOME/.netrc file can contain multiple login definitions, and up
16 macros per login definition.
3 - If the macro's name is "init" it will be executed automatically upon
login. Other macros can be executed from the FTP prompt (ftp> ) with
the syntax "$macro_name".
The following is an example $HOME/.netrc file, specifying one
login definition and one macro.
machine abyss login darin password a1temp
In this example, the first line is a login definition, and it
has the format:
machine \ login \ password \
The second through fourth lines constitute a macro definition. It has
Notice that the macro is terminated by having a blank line after
the last command.
The use of the above example $HOME/.netrc file is as follows:
1 - At the shell prompt, enter "ftp abyss".
2 - FTP scans the $HOME/.netrc file for a login definition for the host
abyss. FTP uses the login definition to log user darin into abyss.
3 - FTP scans for the macro named "init" (associated with this login
definition) and executes the commands the macro specifies, in this
case one put command.
Executing specific macros in the .netrc file
Here is an example of a .netrc file with many
macros being used:
get /etc/motd /tmp/m1
get /etc/motd /tmp/m2
get /etc/motd /tmp3
\< CR >
Each macdef can have ftp subcommands following them.
But there must be a \ carriage return between the
last ftp subcommand and the next macdef.
To execute a specific macro only do the following:
This will run all the subcommands under the macro test1
in the .netrc file.
This will run all the subcommands under the macro test3 in
the .netrc file.
Support Line: Automate FTP transfer ITEM: AE3313L
Dated: December 1994 Category: N/A
This HTML file was generated 99/06/24~13:30:29
Comments or suggestions?