-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_ftp.py
More file actions
38 lines (33 loc) · 1.1 KB
/
Copy pathpython_ftp.py
File metadata and controls
38 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
# coding: utf-8
from ftplib import FTP
import time
import tarfile
import os
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")
ftp.quit()