discovering remote directories via ftp - Protocols

This is a discussion on discovering remote directories via ftp - Protocols ; The ftpdirectory script ( ftp://kermit.columbia.edu/kermit/scr...t/ftpdirectory ) shows how to get a file listing from a remote server. Is it possible to extend this to directory listings? I'd like to be able to script the retrieval of a file from the ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: discovering remote directories via ftp

  1. discovering remote directories via ftp

    The ftpdirectory script
    (ftp://kermit.columbia.edu/kermit/scr...t/ftpdirectory) shows
    how to get a file listing from a remote server. Is it possible to
    extend this to directory listings? I'd like to be able to script the
    retrieval of a file from the most recent directory d.x from [d.1, d.2,
    .... d.z]. At the very least, can I redirect the results of a remote
    dir either to a local variable or to a local file?

  2. Re: discovering remote directories via ftp

    On 2004-08-19, Logan wrote:
    : The ftpdirectory script
    : (ftp://kermit.columbia.edu/kermit/scr...t/ftpdirectory) shows
    : how to get a file listing from a remote server. Is it possible to
    : extend this to directory listings? I'd like to be able to script the
    : retrieval of a file from the most recent directory d.x from [d.1, d.2,
    : ... d.z]. At the very least, can I redirect the results of a remote
    : dir either to a local variable or to a local file?
    :
    If the server includes directories in its NLST reply. Some do, some
    don't. Or if the server supports MLSD:

    http://www.columbia.edu/kermit/newftp.html

    Assuming the server's NLST reply includes directories, you can modify
    the ftpdirectory script to test for this by trying to CD to each file.
    If it succeeds, it's a directory (and you have to remember to CDUP to
    get back where you were); if it fails, it's (probably) an ordinary file.

    undef dir
    ftp cd \m(name)
    if success {
    ftp cdup
    .dir := "(DIRECTORY)"
    }
    echo "\flpad(\m(size),12) \fcvtdate(\m(time)) \m(name) \m(dir)" ; Show info

    Unfortunately, most FTP servers do NOT return directory names in their
    NLST replies, nor do they support MLSD. This is one of many reasons we
    created IKSD:

    http://www.columbia.edu/kermit/iksd.html

    It gets around FTP limitations such as this one, and many others too.

    If the FTP server does not report directories and you can't install IKSD on
    the server, your only other alternative is to use LIST, save the result to
    a file:

    ftp directory * > localfilename

    and "parse" the file.

    - Frank

+ Reply to Thread