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 -*-
"""
Created on Mon Sep 18 12:41:55 2017
@author: hanye
"""
import paramiko
#import scp
from scp import SCPClient
#import datetime
def createSSHClient(server, port, user, password):
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(server, port, user, password)
return client
server = '192.168.17.12'
port = 22
user = 'root'
password = 'Lz8rsAVF'
ssh = createSSHClient(server, port, user, password)
scp = SCPClient(ssh.get_transport())
def scp_from_ftp_server(remote_filename_with_full_path, local_path):
scp.get(remote_path=remote_filename_with_full_path,
local_path=local_path,
preserve_times=True)
def scp_to_ftp_server(local_file_with_full_path, remote_full_path):
scp.put(files=local_file_with_full_path,
remote_path=remote_full_path,
recursive=True,
preserve_times=True)