Retrieving file details from FTP server with ftplib (and 'mlsd'?)

I figured out how to do it fairly simply.

# Retrive a list of files from Fanuc robot FTP server
Import ftplib
import datetime

try:
        ftp.quit()											# Cleanup in case previous script didn't close.
except:
        pass

ftp = ftplib.FTP('10.12.19.19', 'anonymous', '1234')	# Fanuc robot FTP server.
print(ftp.sendcmd('CWD fr:/vision/data'))				# Adapt to suit.
lines = []												# Results
ftp.retrlines('LIST', lines.append)						# Directory listing.
ftp.quit()
# Data retrieved is in format:
# -rw-rw-rw- 1 noone nogroup     178042 nov 18 2021 sf_14_cam1.vd
# ^.........^.........^.........^.........^.........^.........^.........^
# 0         10        20        30        40        50        60        70
for line in lines:
        print(line) 
        print(line[38:49] + " " + line[50:])            # Date and filename.

It doesn’t return the file time but that’s OK in my application.

2 Likes