Chris Hayes
Chris Hayes

Reputation: 4035

Is there a rich ftp client library for Python?

I'm familiar with ftplib and it works great for simple interface but I need file properties and basically a rich ftp client. does anyone know of a good ftp client library?

Upvotes: 2

Views: 2152

Answers (2)

jgomo3
jgomo3

Reputation: 1223

The ftputil could be what you are looking for:

The FTPHost objects generated with ftputil allow many operations similar to those of ​os and ​os.path.

The API supports well file information gathering.

Upvotes: 1

Dietrich Epp
Dietrich Epp

Reputation: 213508

Use the MLSD command. You have to parse it yourself but it's fairly easy.

# Note that portions of MLSD data are case insensitive...
def parseinfo(info):
    for fact in info.split(';'):
        if not fact:
            continue
        name, value = fact.split('=', 1)
        yield name.lower(), value

ftp = ftplib.FTP(host, user, passwd)
dirinfo = {}
def callback(line):
    info, fname = line.split(' ', 1)
    dirinfo[fname] = dict(parseinfo(info))
ftp.retrlines('MLSD {}'.format(path), callback)
print(dirinfo)

That's about as rich as FTP gets.

Upvotes: 4

Related Questions