configuration for ftp script in main script

Hi,

I am new to shell scripting,and i was planning to write a script that will FTP files to destination folder.
I was planning that All configuration should be done through a properties files. and finally the output should be
Files are transferred

I have developed a properties file named ftp.properties and the content of this file are...

# these are the sample valus taken
135.23.34.212 userid password sourcefolder destfolder

135.23.34.212 is the remote ip and rest all is clear

I have also developed another main script file named ftp_script.sh which will read the properties file(ftp.properties)
contents are...

#!/bin/sh 
while read line
do
        RemoteIP=`echo $line | cut -d' ' -f1`
        userid=`echo $line | cut -d' ' -f2`
        passd=`echo $line | cut -d' ' -f3`
        spath=`echo $line | cut -d' ' -f4`
        dpath=`echo $line | cut -d' ' -f5`
        ftp -vin >> ftp.log <<-!
        open $RemoteIP
        user $userid $passd
        cd $dpath
        lcd $spath
        put $file
        bye
        !
done</your/ftp/properties/filepath/ftp.properties

Now I want to change the structure of my properties file(ftp.properties) in the below format...

#############################################

#Properties file for Ftp files

#############################################


#remote ip of the machine 
RemoteIp=135.23.34.212

#This is the source directoy from where the files will be picked up
SrcFolders=/home/Administrator/files


#This directory path should end with a slash(/)
DestFolder=/home/Administrator/output/


#the pattern of the files
SourcefilePattern=*.xml


# your user id 
userid=youruserid


#your password 
password=yourpassword

Could you please guide me what should be the contents of main script file named ftp_script.sh ...as now there will be changes in
ftp_script.sh....!!

You can directly source the properties files. That is add this line at the beginning of your ftp script:

. ftp.properties

Then you can access the properties with variable like "$RemoteIp".

Hi,
so if I write the main script file which will read the properties file .. in this format itself ....

#############################################  
#Properties file for Ftp files
  #############################################  

 #remote ip of the machine
  RemoteIp=135.23.34.212  

#This is the source directoy from where the files will be picked up
 SrcFolders=/home/Administrator/files  

 #This directory path should end with a slash(/)
 DestFolder=/home/Administrator/output/   

#the pattern of the files
 SourcefilePattern=*.xml   

# your user id
  userid=youruserid 

  #your password  
password=yourpassword

followed by main script file.....

#!/bin/sh 
. ftp.properties


rip=$(sed '/^\#/d' archive.config | grep 'RemoteIp'  | tail -n 1 | cut -d "=" -f2-)
srcdir=$(sed '/^\#/d' archive.config | grep 'SrcFolders'  | tail -n 1 | cut -d "=" -f2-)
destdir=$(sed '/^\#/d' archive.config | grep 'DestFolder'  | tail -n 1 | cut -d "=" -f2-)
filepattern=$(sed '/^\#/d' archive.config | grep 'SourcefilePattern'  | tail -n 1 | cut -d "=" -f2-)
userid=$(sed '/^\#/d' archive.config | grep 'userid'  | tail -n 1 | cut -d "=" -f2-)
passd=$(sed '/^\#/d' archive.config | grep 'password'  | tail -n 1 | cut -d "=" -f2-)
ftp -vin >> ftp.log <<-!
        open rip
        user $userid $passd
        cd destdir
        cd srcdir
        put $file
        bye
        !
done

will work ...!!! please guide me on this..!!:confused:

You can directly use the variables from ftp.properties. Parsing the file is not necessary. The code will look like this:

#!/bin/sh

. ftp.properties

ftp -vin >> ftp.log <<-!
        open $RemoteIp
        user $userid $password
        cd $DestFolder
        lcd $SrcFolders
        put $SourcefilePattern
        bye
        !
1 Like

Hi,

I was planning that my properties file instead of the remote ip should contain the url of the ftp server than in this process what changes would occur in my script file....please guide me ..!!:confused::confused: