Script for Automate file transfer from local to remote server

Script for Automate file transfer from local to remote server

Below script will help to create a automate script for file transfer from local to remote server

 Note :- Below parameter values need to change
1) path_to_save_script :- This is local server path where you want to save transfer.sh file
2) user :- user is the name of user by which you can login to remote server
3) ip :- ip is the IP address of remote server
4) password :- password is the password for user and ip mentioned above
5) path_to_local :- This is the path of local machine from where you need to transfer file
6) path_to_remote :- This is the path of remote server where need to transfer files from local server

x=`perl -MPOSIX=strftime -le 'print strftime("%b%d%Y", localtime(time-86400))'`
echo   "#!/usr/bin/expect">>/path_to_save_script/transfer.sh
echo   "spawn  sftp -oPort=port number" user@ip>>/path_to_save_script/transfer.sh
echo   "expect password:" >> /path_to_save_script/transfer.sh
echo   "send \""password"\r\"" >> /path_to_save_script/transfer.sh
echo   "set timeout 1200000" >>/path_to_save_script/transfer.sh
echo   "expect sftp> " >>/path_to_save_script/transfer.sh
echo   "send \"lcd /path_to_local/\r\"" >>/path_to_save_script/transfer.sh
echo   "expect sftp> " >>/path_to_save_script/transfer.sh
echo   "send \"cd /path_to_remote/\r\"" >>/path_to_save_script/transfer.sh
echo   "expect sftp> " >>/path_to_save_script/transfer.sh
echo   "send \"put file_name_*$x*\r\"" >>/path_to_save_script/transfer.sh
echo   "expect sftp> " >>/path_to_save_script/transfer.sh
echo   "send \"quit \r\n\"" >>/path_to_save_script/transfer.sh
chmod +x /path_to_save_script/transfer.sh
cd /path_to_save_script;
./transfer.sh

No comments:

Post a Comment