Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #filename: ftptest.py
- #Synchronize your torrentbox with the torrentfiles you downloaded on your working machine =D
- import ftplib, os, glob, time, sys
- #some variables
- ftpserver = '192.168.1.102'
- user = ''
- password = ''
- torrents = []
- localdir = '/home/path/to/torrentz/zzz/'
- ftpdir = '/remote/torrentbox/torrentpath'
- #Script works from here
- os.system("clear")
- os.chdir(localdir)
- torrents = glob.glob('*.torrent')
- if torrents == []:
- sys.exit("No torrentfiles found in " + localdir)
- else:
- amount = str(len(torrents))
- print "Found " + amount + " torrenfiles in " + localdir
- time.sleep(1)
- print "Connecting to: " + ftpserver
- time.sleep(1)
- ftp = ftplib.FTP(ftpserver)
- print "Logging in..."
- time.sleep(1)
- ftp.login(user, password)
- #logged in! set the working dir
- ftp.cwd(ftpdir)
- #all done:
- counter = 0
- print "Transfering torrentfiles to " + ftpserver
- time.sleep(1)
- while counter < len(torrents):
- localpath = os.getcwd() + '/' + torrents[counter]
- send = 'put ' + localpath + ' ' + ftpdir
- ftp.storbinary("STOR " + torrents[counter], open(torrents[counter], "rb"), 1024)
- counter += 1
- print "All files transfered"
- time.sleep(1)
- ftp.quit()
- print "Deleting torrentfiles in: " + localdir
- time.sleep(1)
- for x in torrents:
- os.remove(os.path.join(localdir,x))
- print "All files deleted"
- time.sleep(4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement