python - How to set conditions for python2.7 paramiko SFTP upload? Improper use of else? -


Very new in Python, and coding in general. I am working on CSV file processing and uploading them to the SFTP server. I want to check whether the file exists on the server or not. If it exists, then I want to rename it and store it in another folder then it should be replaced with the updated file. If it does not exist ... I just want to upload the file.

  path2 = '/import/Test/stock_update.csv' ssh = paramiko.SSHClient () paramiko.util log_to_file (log_file) ssh.set_missing_host_key_policy (paramiko.AutoAddPolicy ()) dt = str ( Datetime.datetime.now () NewName = DT + 'stock_update.csv' store = 'import / test / done /' + NewName ssh.connect ('xxxx-mediaserverxxxxxxxxx', port = 22, user name = 'XXXXXXXXX' , Password = 'xxxxxxxxxx') ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command ('ls / tmp') print "output", ssh_stdout.read () #reading execute co'mmand error = ssh_stderr.read () print "hey" Try SFTP = ssh.open_sftp (), output, error, lane (error): sftp.stat (Path2) except for IOError as e: e.errno print Rint errno.ENOENT if e.errno == errno.ENOENT: print 'if' sftp.put ('C: /Test/fun/stock_update.csv', '/ import / test / stock_update.csv',) and : Print 'this is second' sftp.rename ('/ import / test / stock_update.csv', archive) Sftp.put ('C: /Test/fun/stock_update.csv', '/ import / test / stock_update.csv ',) Finally: sftp.close () ssh.close ()  

I think I am using improperly the other? A file is created on the SFTP server, if none exists but nothing has been done if the file exists. Different lines of code work


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -