Query the files of a ftp directory

Posted by ccalpe on 06-Oct-2011 02:59

Hello everybody,

I have a process in OpenEdge 10.1B that goes through all the files in a directory and keep their names in a temporary table. I'm trying to do the same with an FTP directory by adding the user information and password, but it doesn’t work and I do not know if it possible to do it. Any ideas?

Thanks in advance

    DEFINE TEMP-TABLE ttimage FIELD ttimage INDEX ttimage IS UNIQUE PRIMARY ttimage.

    DEFINE VARIABLE chDirectory AS CHARACTER   NO-UNDO.
    DEFINE VARIABLE chInputFrom AS CHARACTER   NO-UNDO EXTENT 3.

    EMPTY TEMP-TABLE ttimage.

    FILE-INFO:FILE-NAME = 'ftp://usuario:password@ftpdirectory/'.

    IF FILE-INFO:FILE-TYPE BEGINS 'D' THEN chDirectory = FILE-INFO:FILE-NAME.   

    IF chDirectory NE '' AND chDirectory NE ? THEN DO:

        INPUT FROM OS-DIR(chDirectory).
       
        REPEAT:       
            IMPORT chInputFrom.

            IF chInputFrom[3] NE 'F':U THEN NEXT.
           
            CREATE ttimage.
            ASSIGN ttimage.ttimage = "http://ftpdirectory/" + chInputFrom[1].

        END.
       
        INPUT CLOSE.   

    END.

All Replies

Posted by Admin on 06-Oct-2011 03:07

I doubt that the ABL client supports FTP access in that way... When on a GUI client, checkout an Active X component that supports FTP

Posted by Admin on 06-Oct-2011 07:15

I doubt that the ABL client supports FTP access in that way...

true, but it could make it for a nice feature isn't it? being able to access resources using URI like that could come in very handy

Posted by Admin on 06-Oct-2011 07:37

true, but it could make it for a nice feature isn't it? being able to access resources using URI like that could come in very handy

Any additional feature would be nice. But I'd bet a fortune, that Progress won't add it to 10.1B anymore.

Depending on the use case, Progress official response might also be to look at Sonic ESB and a file polling service...

Posted by Admin on 06-Oct-2011 07:43

Any additional feature would be nice. But I'd bet a fortune, that Progress won't add it to 10.1B anymore.

i'm not going to take that bet

Depending on the use case, Progress official response might also be to look at Sonic ESB and a file polling service...

and that will make it for a good laugh... adding full blown sonic esb in place just to be able to read from an ftp server does look like a realistic response coming from PSC

Posted by Admin on 06-Oct-2011 07:47

and that will make it for a good laugh...

I'm glad you are having fun on this sad day...

Posted by Admin on 06-Oct-2011 07:52

a sad day indeed but then again we can only do what the man said... make the most of the short time we've got till we leave room for the new to take place of the old.

Posted by egarcia on 06-Oct-2011 08:01

A possible way would be to implement an FTP client using sockets in the ABL or perhaps, just the LIST command.

The RFC document (RFC 959 File Transfer Protocol) can be found at http://www.faqs.org/rfcs/rfc959.html. (TFTP is RFC 1350.)

There are some sample programs in DLC/src/samples/sockets that can give you an idea.

There are some tools that show the data being sent for TCP/IP commands. These tools can be used to help understand the protocol with an actual connection to an FTP site.

Perhaps, someone might have already implementing an FTP client.

I hope this helps.

Posted by Tim Kuehn on 06-Oct-2011 08:20

Years ago I coded a "controller" which would interact with an FTP client on unix using "input-output through". I don't have the code now, but I know it can be done.

Posted by ccalpe on 06-Oct-2011 11:55

Thank you all for your help.

The idea of ​​using input-through that has commented Tim has helped me find a solution that has worked for me.
I use a. bat that connects to the ftp directory, runs the “ls” command and writes a file on disk with the files it contains. Then I only have read the file.
DEFINE VARIABLE chInputFrom AS CHARACTER   NO-UNDO.

DEFINE VARIABLE chInputFile AS CHARACTER   NO-UNDO.

DEFINE VARIABLE chNow       AS CHARACTER   NO-UNDO.

chNow = STRING(YEAR(NOW)) + STRING(MONTH(NOW)) + STRING(DAY(NOW)) + STRING(MTIME).

chInputFile = "C:\ftpdir" + chNow + ".dat".

INPUT THROUGH VALUE("C:\ftpdir.bat " + chNow) NO-ECHO.

INPUT CLOSE.

PAUSE 1.

INPUT FROM VALUE(chInputFile).

REPEAT:

    IMPORT UNFORMATTED chInputFrom.

    CREATE ttimage.

    ASSIGN ttimage.ttimage = "http://ftp//"  + chInputFrom.

END.   

INPUT CLOSE.

OS-DELETE VALUE(chInputFile).

This thread is closed