Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Created on Jul 1, 2010
- @author: dustin
- '''
- from paramiko import * #@UnusedWildImport
- import os
- import platform
- class SSHClient(SSHClient):
- def load_user_host_keys(self, filename=None):
- '''Loads a user key file and returns its filename.'''
- if not filename:
- #Look for the user's key file in various places
- if platform.system() == 'Windows' and os.path.exists("%s/ssh/known_hosts" % os.getenv("APPDATA")):
- # %APPDATA%\ssh\known_hosts on Windows
- filename = "%s/ssh/known_hosts" % os.getenv("APPDATA")
- elif os.path.exists(os.path.expanduser('~/.ssh/known_hosts')):
- # ~/.ssh/known_hosts, if it exists
- filename = os.path.expanduser('~/.ssh/known_hosts')
- elif os.path.exists(os.path.expanduser('~/ssh/known_hosts')):
- # ~/ssh/known_hosts, common on Windows
- filename = os.path.expanduser('~/ssh/known_hosts')
- #Load the key file, if it was found
- if filename:
- self.load_host_keys(filename)
- #No key file was found, attempt to create one
- else:
- try:
- if platform.system() == 'Windows':
- if not os.path.exists("%s/ssh" % os.getenv("APPDATA")):
- os.mkdir("%s/ssh" % os.getenv("APPDATA"))
- filename = "%s/ssh/known_hosts" % os.getenv("APPDATA")
- else:
- if not os.path.exists(os.path.expanduser("~/.ssh")):
- os.mkdir(os.path.expanduser("~/.ssh"))
- filename = os.path.expanduser("~/.ssh/known_hosts")
- except (IOError, OSError):
- pass
- return filename
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement