Home > allocate  [2 examples]

Allocate space for file transfer.

 Examples

Ex. 1. Specify number of bytes of storage to be reserved for the file.
Ex. 2. For files sent with record or page structure a maximum record or page size in bytes can be specified.


Ex. 1.  Specify number of bytes of storage to be reserved for the file.
SET SERVEROUTPUT ON SIZE 1000000;
DECLARE
  fid VARCHAR2(80);
  host VARCHAR2(80)   := '[replace with ftp address]';
  usernm VARCHAR2(80) := '[replace with ftp username]';
  passwd VARCHAR2(80) := '[replace with ftp password]';
  lv_local_file VARCHAR2(255)  := 'c:\winnt\notepad.exe';
  lv_remote_file VARCHAR2(255) := '/home/tester/test.exe';
BEGIN
  fid := fclient_p.createFTPClient;
  fclient_p.login(fid, host, usernm, passwd);

  -- number of bytes of storage to be reserved for the file.
  fclient_p.allocate(fid, 100000);

  fclient_p.representationType(fid, fclient_p.getIMAGE_TYPE);
  fclient_p.storeStream(fid, lv_remote_file, lv_local_file);
  fclient_p.logout(fid);
  fclient_p.remove(fid);
EXCEPTION
  WHEN fclient_p.java_failed THEN
    DBMS_OUTPUT.PUT_LINE(SUBSTR(fclient_p.getErrorWithResponse(fid), 1, 255));
END;
/


Ex. 2.  For files sent with record or page structure a maximum record or page size in bytes can be specified.
SET SERVEROUTPUT ON SIZE 1000000;
DECLARE
  fid VARCHAR2(80);
  host VARCHAR2(80)   := '[replace with ftp address]';
  usernm VARCHAR2(80) := '[replace with ftp username]';
  passwd VARCHAR2(80) := '[replace with ftp password]';
  lv_local_file VARCHAR2(255)  := 'c:\winnt\notepad.exe';
  lv_remote_file VARCHAR2(255) := '/home/tester/test.exe';
BEGIN
  fid := fclient_p.createFTPClient;
  fclient_p.login(fid, host, usernm, passwd);
  fclient_p.structure(fid, fclient_p.getRECORD_STRUCTURE);

  -- number of bytes of storage to be reserved for the file.
  -- For files sent with record or page structure a maximum record or page size
  -- in bytes can be specified.
  fclient_p.allocate(fid, 100000, 100);
 
  fclient_p.representationType(fid, fclient_p.getIMAGE_TYPE);
  fclient_p.storeStream(fid, lv_remote_file, lv_local_file);
  fclient_p.logout(fid);
  fclient_p.remove(fid);
EXCEPTION
  WHEN fclient_p.java_failed THEN
    DBMS_OUTPUT.PUT_LINE(SUBSTR(fclient_p.getErrorWithResponse(fid), 1, 255));
END;
/

If you need to check if allocate is successful add the following snippet of code immediately after the call to allocate: IF fclient_p.getLastResponseReturnCode(fid) = '202' THEN DBMS_OUTPUT.PUT_LINE('Successful'); ELSE DBMS_OUTPUT.PUT_LINE(SUBSTR('Failed, Reason :'||REPLACE(fclient_p.getLastResponse(fid), CHR(10)), 1, 255)); END IF;

© 1999-2003 Bear Claw Inc.