Python中FTP 上传出现10060错误,怎么解决?
#!/usr/bin/python
#-*- coding: utf-8 -*-
from ftplib import FTP
def ftpconnect():
ftp_server = 'XXXXXXX'
port=21
username = 'anonymous'
password = ''
ftp=FTP()
ftp.set_debuglevel(2) #打开调试级别2,显示详细信息
ftp.connect(ftp_server,port) #连接
ftp.login(username,password) #登录,如果匿名登录则用空串代替即可
return ftp
def uploadfile():
remotepath = "/"
ftp = ftpconnect()
bufsize = 1024
localpath = 'd:\\zh.jpg'
fp = open(localpath,'rb')
ftp.storbinary('STOR '+ remotepath ,fp,bufsize) #上传文件
#ftp.set_debuglevel(0)
fp.close() #关闭文件
ftp.quit()
print 'Success'
if __name__=='__main__':
uploadfile()
deone
10 years, 3 months ago