-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8266_Stat_UpLoad.py.bak
More file actions
91 lines (78 loc) · 2.29 KB
/
8266_Stat_UpLoad.py.bak
File metadata and controls
91 lines (78 loc) · 2.29 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import time
import sys
import threading
import socket, traceback
from ftplib import FTP
#udp_received=0
receivedContent=''
def ftp_login():
ftp=FTP()
ftp.set_debuglevel(0)
ftp.connect('218.83.155.184',21)
ftp.login('daiyinger','199105')
return 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(filename = "log.txt"):
ftp=FTP()
ftp.set_debuglevel(0)
ftp.connect('218.83.155.184',21)
ftp.login('daiyinger','199105')
ftp.delete(filename)
ftp.quit()
#print ("ftp down OK")
def find(filename):
return False
def ftp_find(filename = "log.txt"):
ftp=FTP()
ftp.set_debuglevel(0)
ftp.connect('218.83.155.184',21)
ftp.login('daiyinger','199105')
ftp_f_list = ftp.nlst()
if filename in ftp_f_list:
ftp.quit()
#print ("ftp find OK")
return True
else:
ftp.quit()
#print ("ftp find False")
return False
def ftp_down(filename = "log.txt"):
ftp=FTP()
ftp.set_debuglevel(0)
ftp.connect('218.83.155.184',21)
ftp.login('daiyinger','199105')
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)
ftp.quit()
#print ("ftp down OK")
class UDP_Thread():
host = ''
port = 10008
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))
print ('Start')
ftp = ftp_login()
while True:
message, address = s.recvfrom(8192)
#print ('Ups ')
fp = open("8288stat.txt",'w')
curTime = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(time.time()))
fp.write(curTime)
receivedContent=message.decode()+"\n"
fp.write(receivedContent)
fp.close()
ftp_up("8288stat.txt",'199105')
UDP_Thread().start();