Systems Engineering and RDBMS

Putting files on a remote Server (Oracle/Unix)

Posted by decipherinfosys on October 15, 2007

Sometimes, when we are working with the Oracle database, we come across the need to put files on remote server which are to be picked up by some other process or we have to ftp file(s) for backups. One can transfer the file manually by using ftp either to put on the remote server or to get it from the remote server. Manual process has its own disadvantage as it requires human intervention. We can always automate the process and schedule it as a cronjob so that script gets invoked at specific time and file transfer takes place automatically. Following is the small shell script which automates the process of putting the file on the remote server.  Cut and paste following text on a UNIX machine and save it as a shell file (.sh extension).


ftp -n ${ftp_server} << EOF
user ftpuser ftpuser\*
cd /customerdb/ora_bkup
lcd ${exp_dir}
put decipher_backup.dmp

•    First line indicates that we are using bourne shell. This is default for UNIX. Shell is nothing but the command interpreter. It reads command from the key board and executes it. When more than one command is put together in the file, it is called shell script. We can execute the shell script which in turn will execute all the commands within the script.
•    Second and third lines, we are declaring variable and assigning value to it.
•    Fourth line we are invoking ftp connection with –n option.  When –n option is used, it turns off the automatic login and ftp client will not ask for userid and password to connect to remote server. If not, then it will try to login immediately and will prompt for userid and password. ‘<< ’ is a redirection syntax and indicates that anything defined after this will be considered as an input to the ftp command.
•    On the fifth line, we are giving credentials to login to the remote server by providing userid and password.
•    On the sixth line we are changing the directory where we want to put the file.
•    Seventh line, we are using lcd command to change the directory on local machine and hence (lcd), from which we would like to transfer the file.
•    On the eighth line, we are changing the transfer mode to binary. Default is ascii mode. If it is a zip file or export dump file, it is advisable to transfer it in binary mode otherwise during transfer it may get corrupted.
•    In the ninth line, we are using put command to put the file on the remote server.
•    10th line indicates EOF, means redirection is over at this point. So if at all, any other command is used in the script after this point will not be considered as an input and will be executed individually.

In similar fashion, one can get the file from remote server using get command. Script can be enhanced further to check for the success or failure of ftp process as well.

Sorry, the comment form is closed at this time.

%d bloggers like this: