Skip to content

Instantly share code, notes, and snippets.

@jeremyBanks
Created September 16, 2008 01:18
Show Gist options
  • Save jeremyBanks/10970 to your computer and use it in GitHub Desktop.
Save jeremyBanks/10970 to your computer and use it in GitHub Desktop.
[2010-01] simple example using scp from python
#!/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:]))
@sainzayabatkhuu
Copy link

server = "[email protected]" is not working
ssh: connect to host 10.0.1.1 port 22: Connection refused
lost connection
File upload failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment