python socket.error:[Errno 110]连接超时

时间:2014-11-19 23:14:54

标签: python sockets ssh sftp paramiko

我有serverA,serverB和serverC,需要通过serverB将文件从serverC传输到serverA。所以我这样做了:

import paramiko
import os
import sys
import socket

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.10.10.1', username = 'root',password = 'root')

host_serverC = '192.168.1.1'
username_serverC = 'usr_C'
password_serverC = 'pw_C'
path_serverC = '/home/serverC/log/'
file_serverC = 'file1.log'

path_serverB= '/root/'

ssh_stdin,ssh_stdout,ssh_stderr=ssh.exec_command('ls -ltr')
print ssh_stdout.readlines()


def download_files(files, dest, host, path, username, password):
    transport = paramiko.Transport(host)
    transport.connect(username=username, password=password)
    sftp = paramiko.SFTPClient.from_transport(transport)

    for file in files:
        sftp.get(path + file, dest + file)
        sftp.close()

download_files(file_serverC, path_serverB, host_serverC, path_serverC, username_serverC, password_serverC)

ssh.close()

运行程序后,我得到了:     transport = paramiko.Transport(host)     文件" /usr/lib/python2.6/site-packages/paramiko/transport.py",第289行,在 init sock.connect((主机名,端口))     文件"",第1行,连接socket.error:[Errno 110]连接超时

0 个答案:

没有答案