Skip to content

Instantly share code, notes, and snippets.

@mlafeldt
Created February 24, 2011 09:09
Show Gist options
  • Save mlafeldt/841944 to your computer and use it in GitHub Desktop.
Save mlafeldt/841944 to your computer and use it in GitHub Desktop.

Revisions

  1. mlafeldt created this gist Feb 24, 2011.
    24 changes: 24 additions & 0 deletions scp_demo.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/usr/bin/env python

    import sys, paramiko

    if len(sys.argv) < 5:
    print "args missing"
    sys.exit(1)

    hostname = sys.argv[1]
    password = sys.argv[2]
    source = sys.argv[3]
    dest = sys.argv[4]

    username = "root"
    port = 22

    try:
    t = paramiko.Transport((hostname, port))
    t.connect(username=username, password=password)
    sftp = paramiko.SFTPClient.from_transport(t)
    sftp.get(source, dest)

    finally:
    t.close()
    27 changes: 27 additions & 0 deletions ssh_demo.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/usr/bin/env python

    import sys, paramiko

    if len(sys.argv) < 4:
    print "args missing"
    sys.exit(1)

    hostname = sys.argv[1]
    password = sys.argv[2]
    command = sys.argv[3]

    username = "admin"
    port = 22

    try:
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.WarningPolicy)

    client.connect(hostname, port=port, username=username, password=password)

    stdin, stdout, stderr = client.exec_command(command)
    print stdout.read(),

    finally:
    client.close()