-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8266statGet.py
More file actions
73 lines (61 loc) · 1.85 KB
/
8266statGet.py
File metadata and controls
73 lines (61 loc) · 1.85 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import time
import codecs
from ftplib import FTP
def ftp_up(ftp,filename):
bufsize = 1024#设置缓冲块大小
file_handler = open(filename,'rb')#以读模式在本地打开文件
ftp.storbinary('STOR %s' % os.path.basename(filename),file_handler,bufsize)#上传文件
ftp.set_debuglevel(0)
file_handler.close()
#print ("ftp up OK")
def ftp_del(ftp,filename = "log.txt"):
ftp.delete(filename)
#print ("ftp down OK")
def find(filename):
return False
def ftp_login():
ftp=FTP()
ftp.set_debuglevel(0)
ftp.connect('218.83.155.184',21)
ftp.login('daiyinger','199105')
return ftp;
def ftp_find(ftp,filename = "log.txt"):
ftp_f_list = ftp.nlst()
if filename in ftp_f_list:
#print ("ftp find OK")
return True
else:
#print ("ftp find False")
return False
def ftp_down(ftp,filename = "log.txt"):
bufsize = 1024
localfilename = "local.txt"
file_handler = open(localfilename,'wb').write #以写模式在本地打开文件
ftp.retrbinary('RETR %s' % os.path.basename(filename),file_handler,bufsize)#接收服务器上文件并写入本地文件
ftp.set_debuglevel(0)
#print ("ftp down OK")
def ConvertCN(s):
return s.encode('gb18030')
#ftp_down("index.html")
#ftp_up("for.py")
#ftp_del("for.py")
#ftp_find("1.txt")
#ftp_down("log.txt")
sh_header = "#!/bin/sh\r\n"
ftp = ftp_login()
running=True
while running:
time.sleep(1)
if ftp_find(ftp,"8288stat.txt"):
ftp_down(ftp,'8288stat.txt') #cmd.sh log_out.txt
fs =codecs.open('8288stat.txt','r')
lines = fs.read()
print (lines,)
fs.close() # close the file
#ftp_del(ftp,"8288stat.txt")
else:
print ('The while loop is over.')
# Do anything else you want to do here