FTP file upload using shell script on LINUX/UNIX


FTP file upload is not a big task. It is easy to upload file from command line as well as using free X window based FTP clients such gFTP. However, it is often required to automate FTP file upload task using some kind of scripts such as bash. Below is the subroutine in bash that I often use to upload log files to FTP server.
---------------------------------Start----------------------------------->
###Accepts following arguments
### 1. FILE TO UPLOAD
### 2. HOSTNAME TO FTP
### 3. USER NAME
### 4. USER PASSWORD
###

uploadLogs(){ 
     
    FILETOUPLOAD=$1
    HOSTNAME="$2"
    USERNAME="$3"
    PASSWORD="$4"
    ftp -dvin $HOSTNAME <<EOF
      quote USER $USERNAME
      quote PASS $PASSWORD
      mkdir $PLATFORM
      cd $PLATFORM
      binary
      hash
      put $FILETOUPLOAD
      quit
    EOF 
    
}

<--------------------------------End------------------------------------
Bash subroutine above is almost self explanatory. Do you use any other mechanism to automate FTP session or FTP file upload task? If yes then let everyone know in comments below.

By Mandar Pise

Opinions expressed by techsutram contributors are their own.

2 comments:

  1. Useful ftp script...most versions are crap but this one works fine!

    ReplyDelete
  2. Yes worked great. Helped me automate a rather boring monthly backup upload.

    ReplyDelete

    Your valuable comments are welcome. (Moderated)


Instagram