# coding: utf-8
from ftplib import FTP
import time
import tarfile
import os
# !/usr/bin/python
# -*- coding: utf-8 -*-
from ftplib import FTP
def ftpconnect(host, username, password):
  ftp = FTP()
  # ftp.set_debuglevel(2)
  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()
if __name__ == "__main__":
  ftp = ftpconnect("113.105.139.xxx", "ftp***", "Guest***")
  downloadfile(ftp, "Faint.mp4", "C:/Users/Administrator/Desktop/test.mp4")
  #调用本地播放器播放下载的视频
  os.system('start "C:\Program Files\Windows Media Player\wmplayer.exe" "C:/Users/Administrator/Desktop/test.mp4"')
  uploadfile(ftp, "C:/Users/Administrator/Desktop/test.mp4", "test.mp4")
  <a href="ftp://ftp.quit" rel="external nofollow">ftp.quit</a>()
https://www.jb51.net/article/158788.htm

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注