Please give me advice on SSH connection in Python?

A forum for general discussion of the Python programming language.

Please give me advice on SSH connection in Python?

Postby hariharasubramanian » Wed Jul 17, 2013 6:56 am

Hi,
May I know what is the best module to use for SSH connection in Python?
If Code snippet available with example, it will help me more.

Thanks.
Last edited by Yoriz on Wed Jul 17, 2013 5:42 pm, edited 1 time in total.
Reason: changed title
hariharasubramanian
 
Posts: 1
Joined: Wed Jul 17, 2013 6:51 am

Re: SSH module in Python

Postby tnknepp » Wed Jul 17, 2013 2:32 pm

I use paramiko. e.g.

Code: Select all
import paramiko
# Identify user keys
privatekeyfile = 'path to key file'
mykey = paramiko.RSAKey.from_private_key_file(privatekeyfile)

# Connect to remote destination
transport = paramiko.Transport(('ip address',port))
transport.connect(username='uname',pkey=mykey)
sftp = paramiko.SFTPClient.from_transport(transport)

# List remote files
remFiles = sftp.listdir(remDir) # Throws major fit if remote directory is empty.  Maybe best to use "try:"

# Push file to remote machine
sftp.put(localPath, remotePath)


If you are using Linux you should also be able to do system calls.
Python: 2.7 via Anaconda
Numpy: 1.7
Pandas: 0.11
OS: Windows 7
IDE: Spyder/IPython
User avatar
tnknepp
 
Posts: 133
Joined: Mon Mar 11, 2013 7:41 pm

Re: Please give me advice on SSH connection in Python?

Postby ochichinyezaboombwa » Thu Jul 18, 2013 7:06 pm

Code: Select all
>>> import os
>>> os.system("ssh")
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: Please give me advice on SSH connection in Python?

Postby micseydel » Thu Jul 18, 2013 8:02 pm

ochichinyezaboombwa wrote:
Code: Select all
>>> import os
>>> os.system("ssh")

All that automates is opening it for a user, not the actual use of ssh.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1441
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 3 guests