March 10, 2014

Linux FTP Upload from Oracle database.

How can we FTP file transfer from oracle database.
Simple FTP file transfer method in linux. Following script is saved as executable 
which will then be executed by oracle Job. 


#!/bin/bash
HOST='192.168.5.23'; -- FTP Host
USER='oracle';       -- FTP User
PASS='oracle_pass';   -- Password
FDIR='Oracle'; -- Directory
ftp -niv <<EOF_SCRIPT
open $HOST
user $USER $PASS
pwd
lcd /home/oracle/dummy
cd /Oracle/dummy
mput *.*
quit
EOF_SCRIPT
echo -e "FTP transfer complete! \n"


/* I am saving this script as success_file_upload1.sh and created a job 'TEST' 
 for executing the sh file for FTP uploading . */



exec dbms_scheduler.drop_job('TEST');

BEGIN
dbms_scheduler.create_job(
job_name => 'TEST',
job_type => 'executable',
job_action => '/home/oracle/success_file_upload1.sh',
start_date => systimestamp at time zone 'Asia/Calcutta',
job_class => 'DEFAULT_JOB_CLASS',
auto_drop => FALSE,
enabled => TRUE);
END;
/


exec dbms_scheduler.run_job('TEST');


-- Check dba_scheduler_job_run_details view for the details


-- I got this error,
-- ORA-27369: job of type EXECUTABLE failed with exit code: Permission denied

-- I changed ownership for the following file and executed the Job again. 

chown oracle:dba $ORACLE_HOME/bin/extjob


exec dbms_scheduler.run_job('TEST');

ORA-27369: job of type EXECUTABLE failed with exit code: 274662


-- listed the file
ls -ltr extjob

-rwsrwxr-x 1 root dba /sdb1/app/oracle/product/12.1.0/db_1/bin/extjob

-- Then I have edited the file. Job is not created in SYS schema so we need to add the credentials to following file. 

vi $ORACLE_HOME/rdbms/admin/externaljob.ora

run_user = oracle
run_group = dba

-- Now we can Success fully uploaded through FTP. 


to remote location
------------------

ORA-27369: job of type EXECUTABLE failed with exit code: Operation not permitted

Configure SSH / SCP Without Password in Linux
or check the file is already installed.

Then will be success. 

No comments: