Old boy Education daily-95th Day-shell script Knowledge Point: Write script complete ftp upload download

Source: Internet
Author: User
Tags ftp client

Topic

FTP is often used in daily work, sharing and downloading files, for some unfamiliar with ftp command line personnel
Using FTP for Shared file management is a headache.
and FTP If some files need to be uploaded or downloaded regularly every day, it is meaningless for people to repeat the same work.
So how do I write a script that automatically downloads or uploads ftp files?

Answer reference: 1. ftpput.sh uploading files to FTP scripts
#!/bin/sh         #FileName:ftpput.sh     #Function: Uploading a file from a local client to an FTP server        #Version:v0.1          #Author:     #Date: # $ #表示传递给此Shell脚本的参数个数   # -ne means not equal to    if [ $# -ne 2  ]  then      echo  " Usage $0  <local_dir/filename> <remote_dir> "       exit 1  fi     Note: If the number of parameters passed is not equal to 2, that is, prompt for the error message # ip indicates the FTP server IP address    IP=127.0.0.1     #IP =192.168.6.1   # fullname get local file full path name    fullname=$1   # destdir get the FTP remote directory path to upload   DESTDIR=$2 #  basename returns a filename part of a path   #  such as fullname= "/home/sunrier/proj/log/test.log";  #  when Local_ Filename= ' basename  $FULLNAME '   #  final local_filename= "Test.log"   local_filename= ' basename  $FULLNAME '     # destfile represents the path to the FTP server, and the saved file name   destfile= $DESTDIR/$local _filename  #   Automatically upload files to the FTP server, no interactive way ftp -i -n <<ftpit  open  $IP   user  sunrier redhat  bin  passive  cd /home/remote/log/ftpfile   put  $FULLNAME   $DESTFILE   quit  ftpit  exit 0
2. ftpget.sh download files to FTP client script
#FileName:ftpget.sh     #Function: Download a file from the FTP server to the local computer        #Version:v0.1         #Author: #Date:      #  $ #表示传递给此Shell脚本的参数个数   # -ne means not equal to   if [ $# -ne 2   ]  then      echo  "usage $0  <remote_dir/ Filename> <local_dir> "      exit 1  fi #  IP represents the FTP server IP address   IP=127.0.0.1     #IP =192.168.6.1 #  FULLNAME gets the full pathname of the file downloaded from the FTP server   fullname=$1 # destdir gets the directory path of the local computer that is stored by the file downloaded from the FTP server    destdir=$2   # remote_filename Gets the file name downloaded from the FTP server   remote_filename= ' basename   $FULLNAME '    # destfile indicates the local path to the downloaded file, and the file name   destfile= after the local save $DESTDIR/$ Remote_filenameftp -i -n <<ftpit  open  $IP   user sunrier redhat  bin  cd /home /remote/log/ftpfile  get  $FULLNAME   $DESTFILE   quit  FTPIT        exit 0
Note

Today is the 95th Day of the day to accompany you and look forward to your progress .

For questions and answers, please leave a comment in the blog comments section .
Index of the topic of the previous period

http://lidao.blog.51cto.com/3388056/1914205

This article is from the "Lee blog" blog, make sure to keep this source http://lidao.blog.51cto.com/3388056/1948924

Old boy Education daily-95th Day-shell script Knowledge Point: Write script complete ftp upload download

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.