

RE: FTP contents of an rpg variable.

Very neat! Thank you for the excellent explanation AND the example Scott.

Gonna dig into this more soon! ..after I put a fire out.. sigh.

John B.

-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Thursday, August 20, 2009 5:16 PM
To: HTTPAPI and FTPAPI Projects
Subject: Re: FTP contents of an rpg variable.

Hi John,

John Rusling wrote:
> rc = ftp_putraw(sess :filename :?3 :?4);
> What would I pass for peDescr since I don't have a file open ?
> Well...  peReadProc too for that matter ?

When I wrote FTPAPI, I didn't want to lock myself into only being able 
to FTP a certain type of file, or object, etc. I wanted to keep it open 
so I could make it work with any conceivable type of object.  Originally 
it was just stream files, then I added physical files, save files and 
source files...   I can keep adding more as much as I want.

The way I made it flexible is by coding the "put" routine so that it 
doesn't read the file directly.  It calls a subprocedure to read the 
file, and that subprocedure is called by a procedure pointer, so you can 
specify any "read" subprocedure that you like.

That's what ftp_putraw() is for.  It gives you that flexibility, instead 
of FTPAPI reading the file directly, you pass it a subprocedure.  It'll 
call that procedure when it needs to read a file.

All you have to do is code a procedure that reads from your variable 
instead of reading from an actual disk file.  The tricky part is, FTPAPI 
thinks it's reading a block of bytes from a file, so you'll need to 
return your data in that manner (if that makes sense)

The raw procedure in FTPAPI (and also HTTPAPI) is patterned after the 
IFS read() and write() APIs.  That is to say, it's prototype looks liie 

      D my_raw_proc     PR            10i 0
      D   fd                          10i 0 value
      D   data                     32766a   options(*varsize)
      D   size                        10i 0 value

Whenever it wants to read from you, it passes a descriptor (FD) (it 
doesn't know or care what the descriptor is -- it just passes along 
whatever you specified on the FTP_putraw() call), followed by a buffer 
(DATA) to put data into, followed by the size of that buffer (SIZE).

Your procedure returns the length of data that you placed in the "data" 
buffer. Or, it returns 0 to indicate the end of the file (and then 
FTPAPI will stop calling it.)

The trickiest thing here is to understand the 'data' is variable-sized. 
Depending on the version of FTPAPI, it might be 8k, 32k or 64k. FTPAPI 
will tell you how big it is in the "size" parameter.  you need to use 
due caution to make sure you only touch as much of the variable as 
FTPAPI told you to touch.

I've posted an example of sending data from a string, and from an array 
at the following link:
This is the FTPAPI mailing list.  To unsubscribe, please go to:
