| Changes to /trunk/simplessh.py |
r0 vs. r13
Edit
|
r13
|
| /trunk/simplessh.py | /trunk/simplessh.py r13 | ||
| 1 | #-*- coding: utf-8 -*- | ||
|---|---|---|---|
| 2 | |||
| 3 | # Paramiko modülünü kullanıp ssh işlemlerini yapabilen basit bir sınıf. | ||
| 4 | # Copyright (C) 2008 Ömer ÜCEL <omerucel@gmail.com> | ||
| 5 | |||
| 6 | import os | ||
| 7 | import paramiko | ||
| 8 | |||
| 9 | class SimpleSsh: | ||
| 10 | """ | ||
| 11 | ssh = SimpleSsh(host,username,password,port) | ||
| 12 | ssh.upload(local_file,remote_file) | ||
| 13 | ssh.download(remote_file,local_file) | ||
| 14 | del ssh | ||
| 15 | """ | ||
| 16 | def __init__(self,host,username,password,port=22): | ||
| 17 | self.host = host | ||
| 18 | self.username = username | ||
| 19 | self.password = password | ||
| 20 | self.port = port | ||
| 21 | |||
| 22 | self.ssh = paramiko.SSHClient() | ||
| 23 | |||
| 24 | self.connect() | ||
| 25 | |||
| 26 | def __del__(self): | ||
| 27 | self.disconnect() | ||
| 28 | |||
| 29 | def connect(self): | ||
| 30 | self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | ||
| 31 | self.ssh.connect(self.host,self.port,self.username,self.password) | ||
| 32 | self.sftp = self.ssh.open_sftp() | ||
| 33 | |||
| 34 | def disconnect(self): | ||
| 35 | self.ssh.close() | ||
| 36 | |||
| 37 | def upload(self,localpath,remotepath): | ||
| 38 | self.sftp.put(localpath,remotepath) | ||
| 39 | |||
| 40 | def download(self,remotepath,localpath): | ||
| 41 | self.sftp.get(localpath,remotepath) | ||