FTP Example code in Oracle

Source: Internet
Author: User
Tags remote ftp server

http://blog.csdn.net/mashengwang/article/details/5982663

CREATE OR REPLACE DIRECTORY my_docs as '/u01/app/oracle/';
SET serveroutput on SIZE 1000000
@c:/ftp.pks
@c:/ftp.pkb

--Retrieve an ASCII file from a remote FTP server.
DECLARE
L_conn utl_tcp.connection;
BEGIN
L_conn: = Ftp.login (' ftp.company.com ', ' + ', ' ftpuser ', ' FTPPassword ');
Ftp.ascii (p_conn = l_conn);
Ftp.get (P_conn = L_conn,
P_from_file = '/u01/app/oracle/test.txt ',
P_to_dir = ' My_docs ',
P_to_file = ' test_get.txt ');
Ftp.logout (L_conn);
Utl_tcp.close_all_connections;
END;
/

--Send an ASCII file to a remote FTP server.
DECLARE
  l_conn  utl_tcp.connection;
BEGIN
  L_conn: = Ftp.login (' ftp.company.com ', ' + ', ' 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);
  Utl_tcp.close_all_connections;
END;
/

--Retrieve a binary file from a remote FTP server.
DECLARE
  l_conn  utl_tcp.connection;
BEGIN
  L_conn: = Ftp.login (' ftp.company.com ', ' + ', ' ftpuser ', ' FTPPassword ');
  Ftp.binary (p_conn = l_conn);
  Ftp.get (p_conn      = l_conn,
           p_from_file = '/u01/app/oracle/product/9.2.0.1.0/sysman/reporting/gif/jobs.gif ',
           p_to_dir    = ' My_docs ',
           p_to_file   = ' jobs_get.gif ');
  Ftp.logout (l_conn);
  Utl_tcp.close_all_connections;
END;
/

--Send a binary file to a remote FTP server.
DECLARE
  l_conn  utl_tcp.connection;
BEGIN
  L_conn: = Ftp.login (' ftp.company.com ', ' + ', ' ftpuser ', ' FTPPassword ');
  Ftp.binary (p_conn = l_conn);
  Ftp.put (p_conn      = l_conn,
           p_from_dir  = ' My_docs ',
          p_ From_file = ' jobs_get.gif ',
          p_to_file   = > '/u01/app/oracle/jobs_put.gif ');
  Ftp.logout (l_conn);
  Utl_tcp.close_all_connections;
END;
/

--Get a directory listing from a remote FTP server.
DECLARE
  l_conn  utl_tcp.connection;
  l_list  ftp.t_string_table;
BEGIN
  L_conn: = Ftp.login (' ftp.company.com ', ' + ', ' ftpuser ', ' FTPPassword ');
  Ftp.list (p_conn   = l_conn,
           p _dir   = '/u01/app/oracle ',
           p_list   = l_list);
  Ftp.logout (l_conn);
  Utl_tcp.close_all_connections;
  
  IF l_list. COUNT > 0 Then
    for I in L_list.first. L_list.last LOOP
      dbms_ Output.put_line (I | | ': ' | | L_list (i));
    END LOOP;
  END IF;
END;
/

--Rename a file on a remote FTP server.
DECLARE
  l_conn  utl_tcp.connection;
BEGIN
  L_conn: = Ftp.login (' ftp.company.com ', ' + ', ' ftpuser ', ' FTPPassword ');
  Ftp.rename (p_conn = l_conn,
              P_from = '/u01/app/oracle/dba/shutdown ',
              p_to   = '/u01/app/oracle/dba/shutdown.old ');
  Ftp.logout (l_conn);
  Utl_tcp.close_all_connections;
END;
/

--Delete a file on a remote FTP server.
DECLARE
L_conn utl_tcp.connection;
BEGIN
L_conn: = Ftp.login (' ftp.company.com ', ' + ', ' ftpuser ', ' FTPPassword ');
Ftp.delete (P_conn = L_conn,
P_file = '/u01/app/oracle/dba/temp.txt ');
Ftp.logout (L_conn);
Utl_tcp.close_all_connections;
END;
/

--Create A directory on a remote FTP server.
DECLARE
L_conn utl_tcp.connection;
BEGIN
L_conn: = Ftp.login (' ftp.company.com ', ' + ', ' ftpuser ', ' FTPPassword ');
Ftp.mkdir (P_conn = L_conn,
P_dir = '/u01/app/oracle/test ');
Ftp.logout (L_conn);
Utl_tcp.close_all_connections;
END;
/

--Remove A directory from a remote FTP server.
DECLARE
L_conn utl_tcp.connection;
BEGIN
L_conn: = Ftp.login (' ftp.company.com ', ' + ', ' ftpuser ', ' FTPPassword ');
Ftp.rmdir (P_conn = L_conn,
P_dir = '/u01/app/oracle/test ');
Ftp.logout (L_conn);
Utl_tcp.close_all_connections;
END;
/

FTP Example code in Oracle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.