Skip to content

Instantly share code, notes, and snippets.

@prashanta
Created January 21, 2010 07:05
Show Gist options
  • Save prashanta/282643 to your computer and use it in GitHub Desktop.
Save prashanta/282643 to your computer and use it in GitHub Desktop.
SSH connection from Python
import paramiko
import string
import webbrowser
import os
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.1.21', username='username', password='password')
print "1: get file \n2: print contents of file"
c=input(':')
if c==1:
ftp = ssh.open_sftp()
ftp.get('log.txt', 'log.txt')
ftp.close()
webbrowser.open_new(os.getcwd()+"/log.txt")
print "FILE GOT!"
elif c==2:
ftp = ssh.open_sftp()
file=ftp.file('log.txt', "r", -1)
data=file.read()
L = string.split(data)
for i in L:
if string.find(i, '%')>-1:
print i
print ftp.stat("log.txt")
ftp.close()
print "DONE!"
else:
print "EXIT!"
ssh.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment