In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Because the ssoc logs are huge, they quickly fill up the disk. Need to upload the backup to the ftp server every day, so according to the information on the Internet, I made a simple script. It's the first time I've cobbled together a script. It's also simple, especially the simplification of exception handling. Because of its singleness, the screen output is then written directly to the local file with the pipe command, which acts as a log. It's a lazy version. It needs to be processed.
1 ftp upload the contents of the folder
Delete the files in the existing directory after uploading.
The advantage of simplification is to simply traverse the file and upload it if there is a new file.
The code is as follows:
Import ftplib
Import os
Import shutil
Import time
Def ftpconnect ():
Ftp_server = 'x.x.x.x' # FTP server ip address
Username = 'xxxx'
Password = 'xxxx'
Timeout = 30
Port = 21
Ftp = ftplib.FTP () ftp.set_debuglevel (2) # open debuglevel 2, can display detail messageftp.connect (ftp_server, port, timeout) # connect to FTP serverftp.login (username, password) return ftp
Def uploadfile_to_FTP ():
Ftp = ftpconnect ()
Print ftp.getwelcome () # can display FTP server welcome message.
Bufsize = 1024for filename in os.listdir (r "/ data/data/event"): remotepath = "/ safe-logs/" + filename localpath = "/ data/data/event/" + filename fp = open (localpath, 'rb') ftp.storbinary (' STOR'+ remotepath, fp, bufsize) # start to upload file: local-- > FTP serverftp.set_debuglevel (0) # close debugfp.close () # close connectftp.quit () # quit FTP server
Def cleanfile ():
Shutil.rmtree ("/ data/data/event")
Os.mkdir ("/ data/data/event")
Def print_time ():
Localtime=time.asctime (time.localtime (time.time ()
Print'\ n'
Print "localtime:", localtime
If name = = "main":
Downloadfile_from_FTP () print_time () uploadfile_to_FTP () cleanfile ()
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.