#!/usr/bin/env python
#-*- coding: utf-8 -*-
#-*- 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()
本文展示了一个Python脚本示例,该脚本通过FTP协议将本地文件上传到远程服务器指定目录。首先连接到FTP服务器并登录,然后切换到目标路径,最后上传文件。
3923

被折叠的 条评论
为什么被折叠?



