现在的位置: 首页 > 综合 > 正文

用python通过ftp将文件上传到服务器

2013年08月15日 ⁄ 综合 ⁄ 共 374字 ⁄ 字号 评论关闭
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from ftplib import FTP
import sys,getpass,os.path

host = '10.1.1.1'
username ='test'
password = 'test'

localfile ='E:\\ftp_test.txt'
remotepath ='/test/test/test'
print "HELLO"
f =FTP(host)
f.login(username,password)
print "Welcome:",f.getwelcome()
f.cwd(remotepath)
fd = open(localfile,'rb')
f.storbinary('STOR %s' % os.path.basename(localfile),fd)
fd.close()

f.quit()

抱歉!评论已关闭.