Last active
August 28, 2018 18:02
-
-
Save idaWHALE/f1630b3dd0b62421614ba9903533716f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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