Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. #!/usr/bin/python
  2. #filename: ftptest.py
  3.  
  4. #Synchronize your torrentbox with the torrentfiles you downloaded on your working machine =D
  5.  
  6. import ftplib, os, glob, time, sys
  7.  
  8. #some variables
  9. ftpserver = '192.168.1.102'
  10. user = ''
  11. password = ''
  12. torrents = []
  13. localdir = '/home/path/to/torrentz/zzz/'
  14. ftpdir = '/remote/torrentbox/torrentpath'
  15.  
  16.  
  17. #Script works from here
  18. os.system("clear")
  19. os.chdir(localdir)
  20. torrents = glob.glob('*.torrent')
  21. if torrents == []:
  22.     sys.exit("No torrentfiles found in " + localdir)
  23. else:
  24.     amount = str(len(torrents))
  25.     print "Found " + amount + " torrenfiles in " + localdir
  26.     time.sleep(1)
  27.  
  28. print "Connecting to: " + ftpserver
  29. time.sleep(1)
  30. ftp = ftplib.FTP(ftpserver)
  31. print "Logging in..."
  32. time.sleep(1)
  33. ftp.login(user, password)
  34. #logged in! set the working dir
  35. ftp.cwd(ftpdir)
  36. #all done:
  37. counter = 0
  38. print "Transfering torrentfiles to " + ftpserver
  39. time.sleep(1)
  40. while counter < len(torrents):
  41.     localpath = os.getcwd() + '/' + torrents[counter]
  42.     send = 'put ' + localpath + ' ' + ftpdir
  43.     ftp.storbinary("STOR " + torrents[counter], open(torrents[counter], "rb"), 1024)
  44.     counter += 1
  45. print "All files transfered"
  46. time.sleep(1)
  47. ftp.quit()
  48.  
  49. print "Deleting torrentfiles in: " + localdir
  50. time.sleep(1)
  51. for x in torrents:
  52.     os.remove(os.path.join(localdir,x))
  53. print "All files deleted"
  54. time.sleep(4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement