Python 上传ftp

from ftplib import FTP
def upload_ftp(filename):
try:
    ftp = FTP()
    ftp.set_debuglevel(2)
    #地址
    ftp.connect('192.1.59.23','21')
    #账号和密码
    ftp.login('user','password')
    buf_size = 1024
    f = open(filename,'rb')
    ftp.storbinary('STOR DataResult/DataSupport/%s'%os.path.basename(filename),f,buf_size)
    ftp.set_debuglevel(0)
    f.close()
    ftp.quit()
    return True
except Exception,e:
    print repr(e)
    return False

你可能感兴趣的:(Python 上传ftp)