SHARE
TWEET

Untitled

a guest Jun 18th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import paramiko, sys, os,time
  2.  
  3. host = 'ftp address'
  4. port = 22
  5. transport = paramiko.Transport((host, port))
  6. password = "pass"                   #hard-coded
  7. username = "user"                   #hard-coded
  8. transport.connect(username = username, password = password)
  9.  
  10.  
  11. sftp = paramiko.SFTPClient.from_transport(transport)
  12. print 'SFTP Client initiated'
  13.  
  14. remotepath = "/remote folder/"
  15. localpath = '/local folder/'
  16.  
  17. for file in sftp.listdir('.'):
  18.     fullpath   = os.path.join('.',file)
  19.     timestamp  = os.stat(fullpath).st_ctime # get timestamp of file
  20.     createtime = datetime.datetime.fromtimestamp(timestamp)
  21.     now = datetime.datetime.now()
  22.     delta = now -createtime
  23.     if delta.hours > 2:
  24.         sftp.get(file,localpath)
  25.         sftp.remove(file)
  26.  
  27. sftp.close()
  28. transport.close()
  29.      
  30. timestamp  = sftp.stat(fullpath).st_atime  # get timestamp of file in epoch seconds
  31. createtime = datetime.datetime.now()
  32. now        = time.mktime(createtime.timetuple())
  33. datetime.timedelta = now - timestamp
  34.  
  35. if datetime.timedelta> x:
  36.     do something
  37.      
  38. remotepath = '.'
  39. for file in sftp.listdir_attr(remotepath):
  40.     filepath = remotepath + '/' + file.filename
  41.     timestamp = file.st_mtime
  42.     createtime = datetime.datetime.fromtimestamp(timestamp)
  43.     now = datetime.datetime.now()
  44.     delta = now -createtime
  45.     if delta.hours > 2:
  46.         sftp.get(filepath, localpath)
  47.         sftp.remove(filepath)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top