pythonftpftplibftputil

ftputil throwing "530 Please login with USER and PASS" error on login with blank credentials while ftplib does not


Getting the following error when trying to connect to ftp host with ftputil:

ftputil.error.PermanentError: 530 Please login with USER and PASS.

However I do not get this error when connecting with ftplib. I would like to use ftputil for some of its additional functionality.

import ftputil
import ftplib

host = 'ftp.swpc.noaa.gov'
user = ''
pw = ''
# works
ftp_host = ftplib.FTP(host, user, pw)
ftp_host.login()
# does not work
ftp_host = ftputil.FTPHost(host, user, pw)
# with ftputil.FTPHost(host, user, pw) as ftphost:
#     ftphost.listdir(ftphost.curdir)

Solution

  • ftplib converts a blank user name to "anonymous". Apparently, ftputil doesn't. By changing the user name, it works

    import ftputil
    
    host = 'ftp.swpc.noaa.gov'
    user = 'anonymous'
    pw = ''
    with ftputil.FTPHost(host, user, pw) as ftphost:
        print(ftphost.listdir(ftphost.curdir))
    

    output:

    ['pub']