Shell Script Programming-Example _ Automatic login FTP backup

Source: Internet
Author: User
Tags cos

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.