Create a permission 600 in your own home, named .Netrc file, content:
Machine 192.168.0.1 Login Test Password Test
In this way, you will help you with user name Test, password TEST.
Automatic FTP can be implemented using this feature.
For example, you want to get the file Test.txt on the / Test directory every day, you can do this:
Create a file ftp_cmd, the content is:
CD test
Get test.txt
BYE
Then use crontab -e to set the timing task:
0 5 * * * FTP 192.168.0.1 Automatic transmission of files between UNIX systems with FTP Lu Shoudong ---- In UNIX system, FTP file transfer is one of its most basic application layer services, supported by TCP / IP File Transfer Protocol (FTP), which allows users on a computer from Another computer acquires files, and also allows files to be sent to another computer, ensuring the reliability of file transfer, and the security of FTP is mainly to give users their own accounts and passwords on another computer. To be done. This paper briefly introduces how to use FTP to implement automatic transmission of files with FTP. ---- The author's library has two UNIX servers, the operating system is SCO UNIX Release 3.2V4.2, the application software is a set of library computer management integration systems developed by Informix-4GL (V2.10), system There are two databases, namely book databases, and newspaper databases, and files are saved in /usr/lsd/lsd_tssjk/tssjk.dbs and /usr/lsd/lsd_bksjk/bksjk.dbs two directories. The two servers achieve interconnections through the TCP / IP protocol, and their effects have different, one for the business is used (hereinafter referred to as server a), the IP address is 192.168.0.82, and the other is a data backup (hereinafter referred to as " For server b), it is also available to readers, and the IP address is 192.168.0.81. We envisage to transfer the database files of the server A to the server B via the FTP. Typically, FTP uses the user's interactive input command and executes, which is inconvenient for actual work (especially when some files frequently transferred). Automatic transmission of files can be implemented by the method steps described below. ---- 1. Create a user account ABC in the two servers, and set its password to ABC123. ---- 2. Modify the .profile file under the server A user ABC. Add statements to the beginning of the start: Trap "0 1 2 3 15 # Mask interrupt, mainly to avoid user # 按 中 中 中 程序 执行 程序 加 加 语 语: SH /USR/LSD/LSD_FTP/ABC01.SH # Call ABC01.SH and execute EXIT # exits, returns to the waiting registration status ---- 3. Create a ABC01.SH file, the file is saved in the server A / USR / LSD / LSD_FTP directory, the content is: ##### ABC01.SH ##### Clear Echo "Wait ..." echo "Step 1 ..." rm * echo "Step 2 ..." tar -cf tssjkdat.tar / usr / lsd / LSD_TSSJK / TSSJK.DBS / *. dat tar -cf tssjkidx.tar /usr/lsd/lsd_tssjk/tssjk.dbs/*.idx echo "Step 3 ..." tar -cf bksjk.tar / usr / lsd / lsd_bksjk / Bksjk.dbs echo "Step 4 ..." "Compress -f tssjkdat.tar compress -f tssjkidx.tar echo" Step 5 ... "compress -f bowsjk.tar echo" OK! "---- The file role Mainly to pack the database files, then compress, so that the file is transmitted. ---- 4. Modify the .profile file under the server b user ABC. Add statements to the beginning of the start: TRAP "0 1 2 3 15 Add statement at the end: sh/usr/lsd/lsd_ftp/abc02.sh # calls ABC02.SH and executes exit ---- 5. Create a ABC02.sh file, which is saved in the server B / USR / LSD / LSD_FTP directory, the content is: ##### ABC02.SH ##### Clear Echo "Wait ..." echo "Step 1 ..." RM * Echo "Step 2 ..." FTP 192.168.0.82 Clear Echo "Step 3 .. "uncompress -f tssjkdat.tar.z uncompress -f tssjkidx.tar.z echo" Step 4 ... "uncompress -f bksjk.tar.z echo" Step 5 ... "Tar -xf tssjkdat.tar Tar - Xf TSSJKIDX.TAR Echo "Step 6 ..." TAR-XF BKSJK.TAR Echo "OK!" ---- This file is mainly through the FTP, and then extract it, unpack it. ---- 6. Create a file .Netrc under the server b user ABC, and change its read and write permissions to mode "600". The content of this file is: Machine 192.168.0.82 login abc password abc123 MacDef init binary bell Hash Prompt! Clear Mget *! Clear Bye ---- This file is to automatically register the corresponding account and password for FTP automatic registration 192.168.0.82 server, and define a macro init . The working process of the init macro is: set the file transfer format type to binary (BINARY); the ring is ringing after each file transfer to remind the user (Bell); the transfer progress (Hash) is displayed during the file transfer; turn off interaction tips Switch (prompt) to subsequent "MGET *" operation (all files in the current working directory of the remote server) can be automatically performed; before and after "Mget *" operation, execute "! Clean" clearing; final "BYE "Exit FTP. Note that the above .NETRC file should end with a space, as a macro is defined in the file, and the macro definition must end with the empty line. ---- Through the above steps, when the transmission is required, first enter the user account ABC and its password ABC123 on the server A. When it re-returns to the waiting registration state, enter the user account ABC on the server B and Its password ABC123, and waits to return to the registration state. As for all operations related to data transmission, all of which are automatically completed by the system according to the user's settings. Everyone can establish a corresponding "control file" through the method described above, and implement the automatic transmission of the relevant documents. ---- Final additional indication: ---- 1. The .profile file is the user environment setting file, and there is corresponding .profile under the main directory of each user account. When the user registers into the system, the command in the .profile file will be automatically executed. ---- 2. The .Netrc file is an FTP script file (Script file), its main function is: ---- 1) Provide the information required for Automatic Registration. The so-called "automatic registration" means that the FTP command starts when the run is running, first checking if there is a .NETRC file in the main directory of the user account. If so, check if the server name to be connected is matched with a .NETRC file. If the match is successful, you will automatically register the corresponding server in accordance with the information in the .NETRC file. ---- 2) Define some common "macro". A macro is actually a set of FTP commands predefined in advance, performing a macro equivalent to perform this set of commands. If the name of the macro is "init", then the init macro will be automatically executed after the last step of the FTP registration. ---- 3. FTP is a file transfer program that can only be transferred one file. If you need to transfer a lot of files, especially when you want to include a directory structure of a file, you can packed the relevant files via the tar command. At the time of transmission, simply transmit the corresponding package file. After getting the package file, use the tar command to unpack it. In addition, in order to reduce the transmission amount of the file, the relevant file can be compressed before transmission, and only the compressed file is transmitted, and after the compressed file is transmitted, it will be decompressed by the uncompress command.