啊峰哥

2.2使用urllib的简单传输

使用urllib传输文件

from urllib.request import urlopen

filename = 'new_1.py'
password = 'password'
#如果设置密码
#remoteaddr = 'ftp://lutz:%s@192.168.191.1/%s;type=i'%(password,filename)
#如果没有设置密码
remoteaddr = 'ftp://192.168.191.1/%s;type=i'%(filename)
print('Downloading...',remoteaddr)

remotefile = urlopen(remoteaddr)
localfile = open(filename,'wb')
localfile.write(remotefile.read())
localfile.close()
remotefile.close()
print('Finished')

 

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

导航