from ftplib import FTP
ftp_host = '127.0.0.1'
ftp_user = 'piky'
ftp_passwd = '123'
ftp_target = 'boot.ini'
#download file
def handle_download(block):
file.write(block)
print '.'
#list the server's files
def handle_list():
ftp.retrlines('LIST')
ftp = FTP(ftp_host)
try:
ret = ftp.login(ftp_user, ftp_passwd)
except os.error:
pass
print ret
file = open(ftp_target, 'wb')
ret = ftp.retrbinary('RETR' + ftp_target, handle_download)
print ret
file.close()
ftp.close()
ftp_host = '127.0.0.1'
ftp_user = 'piky'
ftp_passwd = '123'
ftp_target = 'boot.ini'
#download file
def handle_download(block):
file.write(block)
print '.'
#list the server's files
def handle_list():
ftp.retrlines('LIST')
ftp = FTP(ftp_host)
try:
ret = ftp.login(ftp_user, ftp_passwd)
except os.error:
pass
print ret
file = open(ftp_target, 'wb')
ret = ftp.retrbinary('RETR' + ftp_target, handle_download)
print ret
file.close()
ftp.close()