!/usr/bin/env python
#coding: utf-8
from ftplib import FTP
import os
def ftpconnect(host, username, password):
ftp = FTP()
ftp.connect(host, 21)
ftp.login(username, password)
return ftp
#从ftp下载文件
def downloadfile(ftp, remotepath,localpath):
bufsize = 1024
fp = open(localpath, 'wb')
ftp.retrbinary('RETR ' + remotepath, fp.write, bufsize)
ftp.set_debuglevel(0)
fp.close()
#从本地上传文件到ftp
def uploadfile(ftp, remotepath, localpath):
bufsize = 1024
fp = open(localpath, 'rb')
ftp.storbinary('STOR ' + remotepath, fp, bufsize)
ftp.set_debuglevel(0)
fp.close()
#远程服务器信息
ip = '0.0.0.0'
username = 'etl'
password = 'etl'
#需要传输的文件
remotepath = '/home/etl/111.txt'
localpath = '/home/etl/222.txt'
ftp = ftpconnect(ip,username,password)
downloadfile(ftp, remotepath,localpath)
#调用本地播放器播放下载的视频
os.system('start "C:\Program Files\Windows Media Player\wmplayer.exe" "C:/Users/Administrator/Desktop/test.mp4"')
uploadfile(ftp, remotepath,localpath)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)