啊峰哥

2.1FTP的简单传输

第一个简单的FTP传输实例

from ftplib import FTP

nonpassive = False
filename = 'new_1.py'
dirname = '.'
sitename = '192.168.191.1'                                #连接FTP服务器地址
#如果设置密码
#userinfo = ('username','password') #如果没有设置帐号密码userinfo = () print('Connecting...') connection = FTP(sitename) connection.login(*userinfo) connection.cwd(dirname) if nonpassive: #force active FTP if server requires connection.set_pasv(False) print('Downloading...') localfile = open(filename,'wb') connection.retrbinary('RETR '+filename,localfile.write,1024) connection.quit() localfile.close() print('Finished')

 

posted on 2017-10-08 10:56  啊峰哥  阅读(219)  评论(0编辑  收藏  举报

导航