python FTP SMTP POP3 IMAP DNS

Posted on February 1, 2015
Tags: hacksoft
from ftplib import FTP
FTP_HOST = 'ftp.cs.brown.edu'
FTP_USER = 'anonymous'
FTP_PASS = ''

DOWNLOAD_FILE = "README"

##with FTP_TLS(host=FTP_HOST,user=FTP_USER,passwd=FTP_PASS,timeout=15) as conn:
##    connection.dir()


with FTP(host=FTP_HOST,user=FTP_USER,passwd=FTP_PASS,timeout=15) as conn:
    conn.dir() #ls
# drwxrwxrwt    2 0          0              523817 Oct 22 08:30 incoming
# drwxr-xr-x   33 0          2                2323 Aug 13  2013 pub
# drwxr-xr-x   52 0          2                1087 Feb 11  2016 u

    print(" --- "* 10)
    conn.cwd("pub") #cd pub
    conn.dir()  #ls
    with open(DOWNLOAD_FILE,mode="wb") as file:
        conn.retrbinary(f"RETR {DOWNLOAD_FILE}", lambda data: file.write(data))

POP3 vs IMAP4 vs SMTP