Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.32 KB | None | 0 0
  1. __author__="Diego & Oscary un especial abrazo a Ariel de Argentina por la exelente ayuda en Python"
  2. __date__ ="$08/16/2010 09:53:59 PM$"
  3. from os import path, walk
  4. from ftplib import FTP
  5. from smtplib import SMTP
  6. import mimetypes
  7. from email.MIMEText import MIMEText
  8. import socket
  9. import sys
  10. class Log_finder(object):
  11.     def __init__(self, ftp_server, ftp_user, ftp_pass):
  12.         self.ftp_server=ftp_server
  13.         self.ftp_user=ftp_user
  14.         self.ftp_pass=ftp_pass
  15.         self.smtp_server=""
  16.         self.smtp_user=""
  17.         self.smtp_pass=""
  18.         self.archivosLogs=[]
  19.        
  20.     def sender(self,directorio):
  21.         ftp = FTP(self.ftp_server)
  22.         ftp.login(user=self.ftp_user,passwd=self.ftp_pass)
  23.         ip = socket.gethostbyname(socket.gethostname())
  24.         log_ip = "log/%s"%(ip)
  25.     print '>>>>>>>>>> '+directorio
  26.         if log_ip not in  ftp.nlst():
  27.             ftp.mkd(log_ip)
  28.     ftp.storbinary('STOR '+directorio,directorio)
  29.        
  30.            
  31.     def conecter(self):
  32.         fserver = self.ftp_server
  33.         fuser=self.ftp_user
  34.         fpass=self.ftp_pass
  35.         sserver=self.smtp_server
  36.         suser=self.smtp_user
  37.         spass=self.smtp_pass
  38.         try:
  39.             ftp = FTP(fserver)
  40.             ftp.login(user=fuser,passwd=fpass)
  41.         except BaseException, e:
  42.             print '\n [-] Error: %s ' %(e)
  43.             sys.exit(1)
  44.         else:
  45.             print "[*]Sucessfuly conencted to: %s" %(fserver)
  46.            
  47.         try:
  48.             smtp = SMTP(sserver,587)
  49.             smtp.ehlo()
  50.             smtp.starttls()
  51.             smtp.ehlo()
  52.             smtp.login(suser,spass)
  53.         except BaseException, e:
  54.             print '\n [-] Error: %s ' %(e)
  55.             #sys.exit(1)
  56.         else:
  57.             print "[*]Sucessfuly conencted to: %s" %(sserver)
  58.  
  59.  
  60.  
  61.  
  62.     def buscador(self):
  63.         path_to_search = raw_input("Please enter the path to scan: ")
  64.     for root, dirs, files in walk(path_to_search):
  65.             for archivo in files:
  66.             (shortname, extension) = path.splitext(archivo)
  67.             if extension=='.log':
  68.             self.archivosLogs.append(path.join(root, archivo))
  69.             print 'encontre!!'
  70.         for i in self.archivosLogs:
  71.         self.sender(i)
  72.  
  73. if __name__ == '__main__':
  74.     Log = Log_finder('ftp.t35.com','lexel.t35.com','atletico')
  75.     Log.conecter()
  76.     Log.buscador()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement