FTP is a common application for accessing files, and it is also used for daily backups. This cyclical effort will undoubtedly need to be done through automated scripting. This system is CentOS7
This experiment requires you to do the following:
1. Modify the FTP server configuration file /etc/vsftpd/vsftpd.conf, the anon_upload_enable=yes, the previous comment is removed, that is, allow anonymous users to upload files;
2. Add anon_other_write_enable=yesin the next line, which allows anonymous users to overwrite files with the same name and restart the VSFTPD service configuration to take effect.
[Email protected] cos]$ systemctl restart Vsftpd.service
3. Create the upload directory and give reasonable permission, the command is as follows:
[Email protected] cos]$ mkdir/var/ftp/upload[[email protected] cos]$ chown ftp:root/var/ftp/upload
4. Create an FTP automatic upload download script on another server: autoftp01.sh
[email protected] shell]$ Touch testupload#在本地创建TestUpload用于脚本上传.[email protected] shell]$ cat autoftp01.sh#!/bin/bashGet_filename="Testdownload"Put_filename="Testupload"server_ip="192.168.88.103"USER="Anonymous"PASS=""FTP=/usr/bin/FTP$FTP-N$SERVER _ip<< eofquote USER$USERQuote PASS$PASSBinaryget$GET _filenameCD Uploadput$PUT _filenameEOF
Note : The FTP username and password are written in clear text in the script, which may be a security risk, separating the user name and password,
5. By default, directly with the FTP command and press ENTER will enter the FTP automatic login mode, at this time the FTP command will read the user home directory of the . Netrc file, by default this command does not exist, we can create you one:
Default login anonymous password ' \ n ' # defaults user and blank password
This time we directly with the FTP command can be found to directly login:
[[Email protected] ~]$ ftp 127.0.0.1127.0.0.1 (127.0.0.1). (vsFTPd 3.0.2)331 Please specify the password. successful Login. Remote system type is UNIX. Using binary mode to transfer files.ftp
6. Finally use NETRC automatic Landing, the autoftp01.sh script to autoftp02.sh, you can do the same function. The following:
[Email protected] ~]$Vim autoftp02.sh#!/bin/bashGet_filename="Testdownload"Put_filename="Testupload"server_ip="192.168.88.103"FTP="/usr/bin/ftp"$FTP $SERVER _ip<< Eofbinaryget$GET _filenameCD Uploadput$PUT _filenameEOF
The results are as follows:
[Email protected] shell]$ chmod 777 autoftp02.sh [cos@localhost shell]$ lsautoftp01.sh autoftp02.sh< C3/>testupload[cos@localhost shell]$./autoftp02.sh [cos@localhost shell]$ lsautoftp01.sh autoftp02.sh testdownload testupload
I wish you success. Yes,<< EOF does not know the words can be looked up.
October 17, 2015 22:09:43
Shell Script Programming-Example _ Automatic login FTP backup