#!/usr/bin/python import os import sys import subprocess import datetime import ast import socket import shutil import glob def main(cmdArgs): # This script copies down data using sftp # For sftp, your sdiread key must be $HOME/Client-Testing/sdiread.sshkey # The file will be written under you $HOME directory using the path # of the file on the sdi server # This changes the input from amqpfind to a dictionary eventInfo = ast.literal_eval(cmdArgs[2]) print (eventInfo) runSFTP(eventInfo) def runSFTP(eventInfo): userName = 'sdiread' # get the IP address of the sdi server sdiServerIP = eventInfo['server_ip'] serverPath = eventInfo['path'] localDir = os.path.join(os.environ['HOME'],os.path.dirname(serverPath)[1:]) sftpDataDir = os.path.dirname(serverPath)[1:] shortIP = sdiServerIP.split('.')[0] if not os.path.isdir(localDir): try: os.makedirs(localDir) except Exception, e: print 'cannot make destination directory: ', localDir, e return readKey = os.path.join(os.environ['HOME'],'Client-Testing/keys/sdiread.sshkey') knownHostsFix = ' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ' cmdArgs = ['sftp ', '-o ', '\"IdentityFile=', readKey, '\" ' , knownHostsFix, userName, '@', sdiServerIP, ':', serverPath, ' ', localDir] tcmd = ''.join(cmdArgs) print (' ') print (tcmd) subprocess.call(tcmd,shell=True) return if __name__ == '__main__': main(sys.argv)