Pages

Sunday, January 10, 2016

Example of sftp in batch. Example of ftp in batch.

========================
General
========================
The target is to create a script, that will automatically, via crontab, sftp files from server xxx.xxx.xxx.121 to server xxx.xxx.xxx.120.

========================
Steps
========================

Step A - generate pub key
On server xxx.xxx.xxx.120 - generate file id_rsa.pub and scp it to server xxx.xxx.xxx.121
cd .ssh
ssh-keygen -t rsa
scp id_rsa.pub iu@xxx.xxx.xxx.121

Step B - use pub key
On server xxx.xxx.xxx.121, append the pub_key into authorized_keys file
less id_rsa.pub >> .ssh/authorized_keys

Step C - create sftp batch file
oracle@xxx.xxx.xxx.120:/oracle_db/db2/db_igt/backup_from_121/scripts>% less ftp_commands.txt 

lcd /oracle_db/db2/db_igt/backup_from_121/data
cd /starhome/iu/workarea/ora_exp
mget exp_tza*
bye

Note:
bin - This option is not available in sftp, unlike ftp. This is because sftp works in ssh protocol, so file transfer is always binary.

For complete list of options in sftp file transfer options

Step D -  create sftp main file
oracle@xxx.xxx.xxx.120:/oracle_db/db2/db_igt/backup_from_121/scripts>% less sftp_cmd.sh 

sftp -b ftp_commands.txt iu@xxx.xxx.xxx.121


Step E - execute the script
./sftp_cmd.sh

Reference
sftp in batch options Reference



========================
Example of ftp in batch
========================

Calling command:
ftp -i -s:ftp_files.ini

ftp_files.ini content:
open 111.222.333.444
my_user
my_passwork

lcd WORKAREA
cd remote\directory\workarea

mput *.dat
bye


No comments:

Post a Comment