2
# sshpy v1 by s0urd
# simple ssh client 
# irc.gonullyourself.org 6667 #code

import paramiko
import os

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
privatekey = os.path.expanduser('/home/rabia/private')
mkey = paramiko.RSAKey.from_private_key_file(privatekey)
ssh.connect('78.46.172.47', port=22, username='s0urd', password=None, pkey=mkey)

while True:
      pick = raw_input("sshpy: ")
      stdin, stdout, stderr = ssh.exec_command(pick)
      print stdout.readlines()   
      ssh.close()

When I try to run more then 1 command I get this error:

AttributeError: 'NoneType' object has no attribute 'open_session'

1 Answer 1

5

Looks like it's because at the end of the while loop you do ssh.close() (thus closing the session).

Sign up to request clarification or add additional context in comments.

5 Comments

@zeekay Thanks.. I also have another question, it seems I cannot change directories, how can I go about doing this?
sftp = ssh.open_sftp(); sftp.chdir('path')
Docs: lag.net/paramiko/docs/paramiko.SFTPClient-class.html#chdir. It should work unless the directory doesn't exist.
@zeekay Im doing this: def sftp_chdir(): sftp = ssh.open_sftp(); sftp.chdir('/home/s0urd/web')
The sftp client is changing directories, use it to interact, add/move/remove files, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.