Problem creating a Directory object in Oracle - oracle

The code is this:
Originally:(http://www.oracle-base.com/articles/misc/FTPFromPLSQL.php)
The approach uses a combination of the UTL_TCP and UTL_FILE packages to create a simple FTP API (ftp.pks, ftp.pkb). Once the API is loaded into the appropriate schema simple FTP commands can be initiated as follows:
CREATE OR REPLACE DIRECTORY my_docs AS '/u01/app/oracle/';
SET SERVEROUTPUT ON SIZE 1000000
#c:\ftp.pks
#c:\ftp.pkb
-- Send an ASCII file to a remote FTP server.
DECLARE
l_conn UTL_TCP.connection;
BEGIN
l_conn := ftp.login('ftp.company.com', '21', 'ftpuser', 'ftppassword');
ftp.ascii(p_conn => l_conn);
ftp.put(p_conn => l_conn,
p_from_dir => 'MY_DOCS',
p_from_file => 'test_get.txt',
p_to_file => '/u01/app/oracle/test_put.txt');
ftp.logout(l_conn);
END;
/
The problem is that when I try to create the directory object I get an error saying that Create symbol wasnt expected.
where this line should be created?

Is there anything preceding the create statement line in your script? It looks like there might be something you left off the post.

Related

how i use plsql for sending csv file via FTP?

For the development of a solution of replication and consolidation between 2 schema oracle 10g distant. I want to use the FTP API (ftp.pks, ftp.pkb) to transfer a CSV file to an FTP server. when performing the dedicated procedure for that I have the error
ORA-31024: Parser initialization failed with LPX-54
error while parsing a stream to XOB
and I find no solution, can help me!
PROCEDURE ftpTransfer IS
vConn UTL_TCP.connection;;
vFileName VARCHAR2(50);
vToFile VARCHAR2(200);
BEGIN
fileTransfer(vFileName);
IF vFileName IS NULL THEN
raise_application_error(-20002,'FTP - Erreur de Fichier');
END IF;
vToFile := RPLPKG_PARAMETERS.gServer.sDir||vFileName;
vConn := ftp.login(RPLPKG_PARAMETERS.gServer.sHost, RPLPKG_PARAMETERS.gServer.sHost, RPLPKG_PARAMETERS.gServer.sPort, RPLPKG_PARAMETERS.gServer.sPsw);
ftp.ascii(p_conn => vConn);
ftp.put(p_conn => vConn,
p_from_dir => 'RPLDIRECTORY',
p_from_file => 'HRM10122019.csv',
p_to_file => '/JOURNALS/HRM10122019.csv');
ftp.logout(vConn);
END ftpTransfer;
screenshot

Oracle Datapump: Invalid operation at line 6224

I've a Oracle dump file that I'm trying to import to AWS RDS Oracle 12.1.0.2.v17
database.
The dump file looks like this:
$ strings EXPDP.dmp | head -n 6
_|lM
"PACOPROD"."SYS_EXPORT_SCHEMA_01"
IBMPC/WIN_NT64-9.1.0
unicode
AL32UTF8
12.01.00.00.00
The commands I'm running is:
DECLARE
hdnl NUMBER;
BEGIN
hdnl := DBMS_DATAPUMP.OPEN( operation => 'IMPORT', job_mode => 'SCHEMA', job_name=>null, version=>'COMPATIBLE');
DBMS_DATAPUMP.ADD_FILE( handle => hdnl, filename => 'EXPDP.dmp', directory => 'DATA_PUMP_DIR', filetype => dbms_datapump.ku$_file_type_dump_file);
DBMS_DATAPUMP.METADATA_FILTER(hdnl,'SCHEMA_EXPR','IN (''PACOPROD'')');
DBMS_DATAPUMP.START_JOB(hdnl);
END;
/
The response is:
Error report -
ORA-39002: invalid operation
ORA-06512: at "SYS.DBMS_DATAPUMP", line 6224
ORA-06512: at line 7
The closes similar issue I've found is this, even though it's not exactly the same error message and in my case both source and target db is running 12.1.
I think the issue is one of the following:
A) The DMP file is corrupt.
B) I'm doing something wrong.
I've no clue how to get further though. Where shall I dig or what should I try to go forward?
Try to add a log file to the operation. It some times contain more information:
DBMS_DATAPUMP.ADD_FILE( handle => hdnl, filename => 'EXPDP.log', directory => 'DATA_PUMP_DIR', filetype => dbms_datapump.KU$_FILE_TYPE_LOG_FILE);

FTP a file from a Server's Subfolder using PL/SQL

I'm trying to get a file from a Windows Server to our Oracle Application Server directory named EXT_TAB_DATA.
I have followed the sample of a similar SO post (PL/SQL FTP API binary vs ascii mode), using Tim Hall's FTP Package.
Code Block
set serveroutput on
DECLARE
l_conn UTL_TCP.connection;
BEGIN
L_CONN := FTP.login (p_host => 'sample.corp.server' -- this is a sample, not the real IP address
p_user => 'corporate/user1', -- this is a sample, not the real User
p_port => '21',
p_pass => 'pwd');
ftp.binary(p_conn => l_conn);
ftp.get (p_conn => l_conn,
p_from_file => '101_Test.csv',
p_to_dir => 'EXT_TAB_DATA',
p_to_file => '101_Test_Trans.csv');
ftp.logout(l_conn);
END;
/
However, the file i'm trying to transfer is located in a subfolder named "Payroll_Folder" in "sample.corp.server.
Seems FTP.login only checks the main directory of the host, and not inside subfolders.
How can I get the the file '101_Test.csv' from the Server/Directory "sample.corp.server/Payroll_Folder"?
Change
p_from_file => '101_Test.csv'
to
p_from_file => 'Payroll_Folder/101_Test.csv'

Move a file from one server to another server via plsql or shell

I have a server with details :
server ip: 192.168.141.96 : 21 credentials: user: tss password: T#l30P#ss path: /home/ttt/
This is the server where a file is getting generated. I want to move this file to another server with credentials
Host: sftp://sftpabc.learn.com
User name: abc
Password: jQrE7wvg
Port: 22
import dir: upload/source
I am trying to use the following plsql script for this :
DECLARE
l_conn UTL_TCP.connection;
begin
l_conn := ftp.login('192.168.141.96', '21', 'tss', 'T#l30P#ss');
ftp.ascii(p_conn => l_conn);
FTP.GET(P_CONN => L_CONN,
P_FROM_FILE => 'filename_test.csv',
p_to_dir => 'DIR_INBOUND',
p_to_file => 'test_get.txt');
ftp.logout(l_conn);
END;
But this is not executing and no file is getting transgerred. Is there a shell script/plsql script for this ?
What do you mean by 'is not executing'. What is the error? A quick search shows that you may be using this site as reference for your code. If that is the case, did you make sure to compile the ftp.pks and ftp.pkb in your database?

send mail with existing file as attachments using oracle procedure

DECLARE
attachments shr_pkg_send_mail.array_attachments:=shr_pkg_send_mail.array_attachments();
b_input_file BFILE:= BFILENAME('mount_dir', 'test02.txt');
c_output_file CLOB;
BEGIN
--DBMS_OUTPUT.PUT_LINE(c_output_file);
dbms_lob.open(b_input_file, DBMS_LOB.LOB_READONLY);
-- DBMS_OUTPUT.PUT_LINE('1');
dbms_lob.createtemporary(lob_loc => c_output_file, cache => false);
--DBMS_OUTPUT.PUT_LINE('2');
dbms_lob.open(c_output_file, DBMS_LOB.LOB_READWRITE);
--DBMS_OUTPUT.PUT_LINE('3');
dbms_lob.loadfromfile(c_output_file, b_input_file, DBMS_LOB.LOBMAXSIZE);
--DBMS_OUTPUT.PUT_LINE('4');
dbms_lob.close(b_input_file);
--DBMS_OUTPUT.PUT_LINE('5');
attachments.extend(1);
attachments(1).attach_name := 'test02.txt';
attachments(1).data_type := 'text/plain';
attachments(1).attach_content := c_output_file; SHR_PKG_SEND_MAIL.SEND_MAIL('EthicsandComplianceITSupport_ORG#dl.mgd.novartis.com','mansi.kekre#novartis.com','test','test',attachments => attachments);
dbms_lob.close(c_output_file);
END ;
ERROR
ORA-22285: non-existent directory or file for FILEOPEN operation
ORA-06512: at "SYS.DBMS_LOB", line 1014
ORA-06512: at line 8
Get the directory path
select directory_path from all_directories where directory_name='MOUNT_DIR'
Check if this path exists on database server and oracle has read access to it.
Check if the file 'test02.txt' exits in this path and is accessible.
Give grants to this directory
GRANT READ, WRITE ON DIRECTORY MOUNT_DIR TO <some_user>;
And here is something interesting, how to see files in directory with select, but you should have access to the SYS user.

Resources