Last active
August 29, 2015 14:06
-
-
Save ShahriyarR/695f4c3daa880333ca4d to your computer and use it in GitHub Desktop.
SFTP Connection Class Using Paramiko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import paramiko | |
import os | |
import subprocess | |
class SFTPConnection: | |
""" | |
Class for SFTP Connection using Paramiko | |
""" | |
def __init__(self): | |
paramiko.util.log_to_file('/tmp/paramiko.log') | |
self.host1 = "192.168.1.77" | |
self.port = 22 | |
#self.path = os.path.join(os.environ['HOME'], '.ssh', 'id_dsa') | |
#self.key = paramiko.DSSKey.from_private_key_file(self.path) | |
self.privatekeyfile = os.path.expanduser('~/.ssh/id_rsa') | |
self.mykey = paramiko.RSAKey.from_private_key_file(self.privatekeyfile) | |
self.username = 'root' | |
def connection_to_77(self): | |
""" | |
SFTP connection to 192.168.1.77 server using root user | |
""" | |
transport = paramiko.Transport((self.host1, self.port)) | |
transport.connect(username = self.username, pkey = self.mykey) | |
sftp = paramiko.SFTPClient.from_transport(transport) | |
return sftp | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment