Wednesday, July 1, 2015

File Transfer to Windows Server

# This script will show you how to connect to the Database and windows server connection

#                      #!/bin/ksh
#
# ***********************************************************
# Default Applications Object Library specific Parameters
# ***********************************************************
orauser_pwd=${1}
user_id=${2}
user_name=${3}
request_id=${4}
#
# ***********************************************************
# Program Parameters
# ***********************************************************

P_HOST=$5    #Windows Server ip/host
P_USER=$6    #Windows Server User
P_PASS=$7    #Windows Server Password
P_DIR1=$8    #File Dir
P_FILE=$9    #File Name
#
# ***********************************************************
# Local variables
# ***********************************************************
lc_inst='AKPROD'      

# ***********************************************************
# Connect to the Database and get the File Name/ Instance
# ***********************************************************
lc_sql_rec=`sqlplus -s $orauser_pwd <<+ENDOFSQL+
set echo off
set pages 0
set heading off
set termout off
set feed off
set trimspool on
select substr('$P_FILE',instr('$P_FILE','-',-1)+2)
       ||'#'||(select instance_name FROM v\\$instance)
  from dual;
exit
+ENDOFSQL+`


lc_file_name=`echo $lc_sql_rec | cut -f1 -d'#'`
echo "File Name>"
echo $lc_file_name
echo " "
lc_inst_name=`echo $lc_sql_rec | cut -f2 -d'#'`
echo "Instance>"
echo $lc_inst_name
echo " "


#Start the transfer procedure

#Go to the file directory
cd $P_DIR1

# ***********************************************************
#  Check if it is Prod instance
# ***********************************************************

if [ "$lc_inst_name" = "$lc_inst" ]; then
   lc_windows_dir='/AKFiles/LIVE'
   lc_file_name_win='LIVE_'$lc_file_name
else
   lc_windows_dir='/AKFiles/TEST'
   lc_file_name_win='TEST_'$lc_file_name
fi

echo "Windows File Name>"
echo $lc_file_name_win
echo " "

# ***********************************************************
#  Connect to the Windows Server
# ***********************************************************

ftp -n $P_HOST <<END_SCRIPT
quote USER $P_USER
quote PASS $P_PASS
cd $lc_windows_dir
ascii
put $lc_file_name $lc_file_name_win
get $lc_file_name_win $lc_file_name_win
bye
END_SCRIPT

if [ -f $lc_file_name ]; then

  echo "FTP successful"
  rm $lc_file_name_win

  exit 0

else

  echo "FTP failed"
  exit 1
fi

#*******************End of FTP *****************************

No comments:

Post a Comment