Skip to content

Instantly share code, notes, and snippets.

@idaWHALE
Last active August 28, 2018 18:02
Show Gist options
  • Save idaWHALE/f1630b3dd0b62421614ba9903533716f to your computer and use it in GitHub Desktop.
Save idaWHALE/f1630b3dd0b62421614ba9903533716f to your computer and use it in GitHub Desktop.
import sys
import ConfigParser
import paramiko
import functools
args = sys.argv
zconfig = ConfigParser.RawConfigParser()
zconfig.read(args[1])
compconfig = ConfigParser.RawConfigParser()
compconfig.read(args[2])
fileExt = compconfig.get('DEFAULT', 'fileExt')
# set up paramiko policy for key policy
class AllowAnythingPolicy(paramiko.MissingHostKeyPolicy):
def missing_host_key(self, client, hostname, key):
return
client = paramiko.SSHClient()
client.set_missing_host_key_policy(AllowAnythingPolicy())
client.connect('127.0.0.1', username=zconfig.get('SFTP', 'username'), password=zconfig.get('SFTP', 'password'))
def my_callback(filename, bytes_so_far, bytes_total):
print 'Transfer of %r is at %d/%d bytes (%.1f%%)' % (filename, bytes_so_far, bytes_total, 100. * bytes_so_far / bytes_total)
sftp = client.open_sftp()
sftp.chdir('in/')
for filename in sorted(sftp.listdir()):
# print("filename: {}, localDir: {}, fileExt: {}, filename.split: {}".format(filename, localDir, fileExt, filename.split('.')[1].lower()))
if filename.split('.')[1].lower() != fileExt:
continue
callback_for_filename = functools.partial(my_callback, filename)
sftp.get(filename, localDir + '/' + filename, callback=callback_for_filename)
# filename = filename.split('.')[0] + '.done'
print(filename)
sftp.remove(filename)
client.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment