!python
# -*- coding: utf-8 -*-
'''
ftplib.error_perm 553 could not create file
'''
from ftplib import FTP
import os
def ftpconnect():
ftp_server = '192.168.1.141'
username = 'wwwer'
password = 'wwwer'
ftp=FTP()
ftp.set_debuglevel(2) #打开调试级别2,显示详细信息
ftp.connect(ftp_server, 21) #连接
ftp.login(username, password) #登录,如果匿名登录则用空串代替即可
return ftp
def uploadfile():
remotepath = "/var/www/panda"
ftp = ftpconnect()
ftp.cwd(remotepath)
bufsize = 1024
localpath = '/home/mengxiaowei/srs.monitor/objs/log/monitor/20155/12/201505121355.tmp' #(换成自己的文件路径)
fp = open(localpath, 'rb')
send_cmd = 'STOR 201505121355.tmp' #(这绝对是个大坑,就没有看到文章解释清楚的,这边是上传到ftp服务器的文件名。不要用localpath来拼)
ftp.storbinary(send_cmd, fp)
ftp.set_debuglevel(0)
fp.close() #关闭文件
ftp.quit()
uploadfile()