def ftp_connect(): # Connect to the FTP and start asking for commands
while True: # If connection fails, retry
site_address = input('Enter FTP address: ')
try:
with ftplib.FTP(site_address) as ftp:
ftp.login()
print(ftp.getwelcome())
print('Directory Listing for', ftp.pwd())
ftp.dir()
print('Valid commands are cd/get/exit - ex: get readme.txt')
ftp_command(ftp)
break # once ftp_command() exits, end this function (exit program)
except ftplib.all_errors as e: # treat all exceptions at this point as a connection failure
print('Failed to connect, check your address.', e)
评论列表
文章目录