My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#-*- coding: utf-8 -*-

# Paramiko modülünü kullanıp ssh işlemlerini yapabilen basit bir sınıf.
# Copyright (C) 2008 Ömer ÜCEL <omerucel@gmail.com>

import os
import paramiko

class SimpleSsh:
"""
ssh = SimpleSsh(host,username,password,port)
ssh.upload(local_file,remote_file)
ssh.download(remote_file,local_file)
del ssh
"""
def __init__(self,host,username,password,port=22):
self.host = host
self.username = username
self.password = password
self.port = port

self.ssh = paramiko.SSHClient()

self.connect()

def __del__(self):
self.disconnect()

def connect(self):
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.ssh.connect(self.host,self.port,self.username,self.password)
self.sftp = self.ssh.open_sftp()

def disconnect(self):
self.ssh.close()

def upload(self,localpath,remotepath):
self.sftp.put(localpath,remotepath)

def download(self,remotepath,localpath):
self.sftp.get(localpath,remotepath)
Show details Hide details

Change log

r13 by omerucel on Oct 02, 2008   Diff
simplessh.py
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1097 bytes, 41 lines
Hosted by Google Code