python - Paramiko - sftp.get downloads blank file -


i'm using paramiko connect server via ssh, run command generate report, download report local computer. seems work fine without error, resulting file blank on local computer. i'm using python 2.7 , latest version of paramiko. file i'm trying download .csv . i've verified file contains data server-side.

the code using below:

try:     ssh = paramiko.sshclient()      ssh.set_missing_host_key_policy(paramiko.autoaddpolicy())      ssh.connect(hostname, username=user_name, key_filename=key_file) except:     print 'error connecting'  try:     stdin, stdout, stderr  = ssh.exec_command(report_cmd) except:     print 'error generating report'  try:      sftp = ssh.open_sftp()       sftp.get(source_str, dest_str)  except:     print 'failed dl file' + str(sys.exc_info())  ssh.close() 

you trying download file before ssh.exec_command has finished.

you need wait; best way read stdout and/or stderr until eof.

i think reads blocking, since have nothing else until finish anyway should fine. , beleive eof empty string: "".


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -