On Wed, Nov 8, 2017 at 5:31 PM, Bob Cagle <bcagle@xxxxxxxxxxx> wrote:
I just started looking at Scott's FTPAPI. I agree, it looks quite a bit more functional.
Since this is the offshoot of your post which isn't in the RPG list, I
don't feel too bad about throwing in a mention for Python. Getting a
directory listing is simply this in Python:
from ftplib import FTP
ftp = FTP('your.host.here', 'bob', 'pwd')
listing = []
ftp.retrlines('LIST', listing.append)
After executing those four lines of code, `listing` is a list of
strings, each string being a line in the directory listing. If you
just want the names (no dates or file sizes), you would use the
command string 'NLST' instead of 'LIST'.
You can get the standard FTP error/status messages as well (I happened
to not capture it in the sample above, but that fourth line returns
the string '226 Transfer complete.' on success). Essentially all the
same functionality provided by FTPAPI is available in Python's
standard ftplib. There's also a higher-level third-party package
called ftputil which makes FTP sessions feel more like typical Python
local file system operations (and less like raw FTP commands, with
fewer if any callbacks).
John Y.
As an Amazon Associate we earn from qualifying purchases.