def scp_transfer(transfer_job):
 def print_ticks(d):
  pass
 host = transfer_job.params['host']
 user_name = transfer_job.params['user_name']
 password = transfer_job.params['password']
 file_path = transfer_job.params['file_path']
 if (pexpect is None):
  return dict(state=transfer_job.states.ERROR, info=PEXPECT_IMPORT_MESSAGE)
 try:
  (fh, fn) = tempfile.mkstemp()
 except Exception as e:
  return dict(state=transfer_job.states.ERROR, info=('Unable to create temporary file for transfer: %s' % str(e)))
 try:
  cmd = ("scp %s@%s:'%s' '%s'" % (user_name, host, file_path.replace(' ', '\\ '), fn))
  pexpect.run(cmd, events={'.ssword:*': (password + '\r\n'), pexpect.TIMEOUT: print_ticks}, timeout=10)
  return dict(state=transfer_job.states.DONE, path=fn)
 except Exception as e:
  return dict(state=transfer_job.states.ERROR, info=('Error during file transfer: %s' % str(e)))

def scp_transfer ( transfer_job ) : def print_ticks ( d ) : pass host = transfer_job . params [ 'host' ] user_name = transfer_job . params [ 'user_name' ] password = transfer_job . params [ 'password' ] file_path = transfer_job . params [ 'file_path' ] if ( pexpect is None ) : return dict ( state = transfer_job . states . ERROR , info = PEXPECT_IMPORT_MESSAGE ) try : ( fh , fn ) = tempfile . mkstemp ( ) except Exception as e : return dict ( state = transfer_job . states . ERROR , info = ( 'Unable to create temporary file for transfer: %s' % str ( e ) ) ) try : cmd = ( "scp %s@%s:'%s' '%s'" % ( user_name , host , file_path . replace ( ' ' , '\\ ' ) , fn ) ) pexpect . run ( cmd , events = { '.ssword:*' : ( password + '\r\n' ) , pexpect . TIMEOUT : print_ticks } , timeout = 10 ) return dict ( state = transfer_job . states . DONE , path = fn ) except Exception as e : return dict ( state = transfer_job . states . ERROR , info = ( 'Error during file transfer: %s' % str ( e ) ) )
plugin" for handling scp transfers using pexpect .