FTP (file transfer) and E-mail (email), Telnet (remote login) is one of the three main functions of the Internet. Because frequent use, users often encounter a variety of problems, reasonably use the initialization file of the ftp command, so that the internal commands of certain FTPs are automatically executed after running the FTP, which can effectively overcome the inconvenience in various uses. Greatly facilitated FTP users. · There are dozens of commands in the FTP that should be included in the NETRC, and there should be a shortcomings in .NetrC: 1.Default login
Password
In the Internet, there is a large number of anonymous FTP accounts, and users log in to anonymous account between different hosts.
The email address is used as a password, which is extremely cumbersome, it is necessary to use the .NETRC file, automatic when entering FTP
Complete this process.
2.binary
Many users only realize that the downloaded files are binary, but they use the ASCII mode.
Losing, making download files could not be used, and many useless work. Set the transmission mode to binary in advance in the .netrc file, completely
The above is avoided.
3.Runique
Users using the Internet know that in the vast file of the smoke sea, there is a large number of names of the same name, such as Readme, INDEX, etc.
Download the same name to the same directory, the new file will overwrite the original same name file. In order to make the file with potential importance
As for accidental coverage, it is also necessary to set the Runique parameter to prevent the above errors in the .netrc file.
4.Prompt off
When using FTP, the FTP commands that often need to be confirmed are often used to cancel this confirmation process, which can be greatly convenient.
5.hash on
The Hash command in the ftp makes a "#" number on the screen when the file is transmitted, and the user shows a "#" number on the screen.
Look at the "#" number on the screen, you can visually see the speed of transmission, and the transfer of the transfer of the file, to determine further
operating.
6.Idle 7200
At present, the domestic Internet line rate is generally low, but the number of users is sharply expanded, so use FTP to transfer large files.
When it is often broken by the line congestion, the FTP process is interrupted, in order to reduce the number of times the number of times due to the disconnection, Idle is required
The parameter of the command is set to the maximum (typically 7200 seconds).
7.macdef
MacDef defines a macro, macro_name is the name of the macro definition. Under the MacDef, you can enter any valid FTP commands, and
At the end of the macro, just add "$" when executed when executed. If the macro name is defined as init, the macro command is started
After the ftp is automatically executed, no user input $ macro_name.
· NETRC use example
1. Edit a following file with the VI editor:
Default login anonymous password user@my.site
MacDef init
binary.
Runique.
Hash on.
PROMPT OFF
Idle 7200
(Blank)
The first line of line is default, enter an Anonymous account, and use its own email address as a password; second line to eight line definitions
Hong INIT, all 5 commands in this macro will be implemented immediately after entering the FTP environment, the 8th line (blanks) may not be omitted, otherwise
Effect macro definition.
2. Utilize .NETRC can greatly simplify the user's operation, which greatly improves working efficiency. For example, use the Archie command to find the file
XPlaygizMo-1.0.gz's purpose on anonymous FTP hosts Unsite.unc.e
Under the Pub / Packages / Solaris / Freeware, the user wants to download the file with FTP, just use the VI editor to put Archie's
The results of the lookup are inserted into the .Netrc file space, that is, add the following three lines:
CD / PUB / PACKAGES / SOLARIS / FREEWARE
Get XPlaygizmo-1.0.gz
BYE
(Blank)
Run FTP SunSite.Unc.edu, which is automatically completed all of the above .NeeeTRC, without any artificial intervention. Screen will
Show similar to the following results:
Connected to sunsite.unc.edu.
220 Calzone FTP Server (Version WU-2.4 (38) WED 0CT 2 09:30:40 EDT 1996) Ready331 Guest Login OK, Send Your Complete E-mail Address AS Password.
230 ...........
230 Guest login OK, Access RESRICTIONS APPLY.
200 Type Set to I.
Receive unique on.
Hash Mark Printing ON (1024 Bytes / Hash Mark).
Interactive mode OFF.
200 Maximum Idle Time Set To 7200 SECONDS
CD / PUB / PACKAGES / SOLARIS / FREEWARE
250 CWD Command Successful.
Get XPlaygizmo-1.0.gz
200 Port Command Successful.
150 Opening Binary Mode Data Connection for XPlaygizMo-1.0.gz (8753 Bytes).
########
226 Transfer Complete.
8753 BYtes Received in 50.8 SECS (0.17 kbytes / sec)
221 Goodbye.
When the default, run the ftp command will detect the .Netrc file in the home directory of the user, and automatically execute, if you don't want to make
Use the .Netrc to cancel the -n parameter in the FTP command line.
There are a few points in this there, no mention:
1. The authority of .Netrc must be 600
2. If you want to set an IP, you need to command
Machine IP_ADDR
3. Macro INIT can be executed automatically, if you define other macros, use $ macro_name when executed
Machine 192.168.1.15
# Host2 for the host name for backup
Login Local
#local is a user on the backup host
Password local
#local user's password is LOCAL
MacDef init
# Define a macro called init, it will be executed in the automatic registration process
binary
# The transfer mode of the file is set to binary
LCD / App / DUMP
# Enter the local working directory / DUMP
CD / DUMP
# Enter backup host directory / DUMP
MPUT
# Transfer all files in / dump directory to backup hosts
BYE
# 退出FTP session process
Blank line
Note (1) CHMOD 600 .NETRC (2) Put it in the user directory (3) Last Bye has a blank problem after you can use a Code solution: #! / Usr / bin / expert # you can pass your host name From command line spawn ftp ftp.name expert "name" send "anonymous / r" expect "password:" send "Yourname @ domain / r" EXPECT "ftp>" Interact If you want Error Checking, define wants Function your function while loop in which you can BTW:. expect is tcl-based language ftp -vin << ENDopen 10.1.1.1user username passwordbinaryget filebyeEND built a file ftpget, content is open 10.1.1.1user username passwordbinaryget filebye.