Created
          September 16, 2008 01:18 
        
      - 
      
- 
        Save jeremyBanks/10970 to your computer and use it in GitHub Desktop. 
    [2010-01] simple example using scp from python
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | #!/usr/bin/env python | |
| # encoding: utf-8 | |
| from __future__ import with_statement | |
| import sys | |
| import subprocess | |
| def scp(source, server, path = ""): | |
| return not subprocess.Popen(["scp", source, "%s:%s" % (server, path)]).wait() | |
| def main(*args): | |
| filename = "example.txt" | |
| server = "[email protected]" | |
| with open(filename, "w") as f: | |
| f.write("Hello world.") | |
| if scp(filename, server): | |
| print("File uploaded successfully.") | |
| return 0 | |
| else: | |
| print("File upload failed.") | |
| return 1 | |
| if __name__ == "__main__": sys.exit(main(*sys.argv[1:])) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
server = "[email protected]" is not working
ssh: connect to host 10.0.1.1 port 22: Connection refused
lost connection
File upload failed.