fabirc的get或者put抛出的paramiko.ssh_exception.SSHException: Channel closed.

内容抛出错误如下

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/fabric/main.py", line 743, in main
    *args, **kwargs
  File "/Library/Python/2.7/site-packages/fabric/tasks.py", line 368, in execute
    multiprocessing
  File "/Library/Python/2.7/site-packages/fabric/tasks.py", line 264, in _execute
    return task.run(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/fabric/tasks.py", line 171, in run
    return self.wrapped(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/fabric/decorators.py", line 53, in inner_decorator
    return func(*args, **kwargs)
  File "/Users/sunchao/oe_dev/fabfile.py", line 227, in uat_down
    get('~/xxx.dump', '~/')
  File "/Library/Python/2.7/site-packages/fabric/network.py", line 639, in host_prompting_wrapper
    return func(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/fabric/operations.py", line 528, in get
    ftp = SFTP(env.host_string)
  File "/Library/Python/2.7/site-packages/fabric/sftp.py", line 30, in __init__
    self.ftp = connections[host_string].open_sftp()
  File "/Library/Python/2.7/site-packages/paramiko/client.py", line 345, in open_sftp
    return self._transport.open_sftp_client()
  File "/Library/Python/2.7/site-packages/paramiko/transport.py", line 711, in open_sftp_client
    return SFTPClient.from_transport(self)
  File "/Library/Python/2.7/site-packages/paramiko/sftp_client.py", line 101, in from_transport
    chan.invoke_subsystem('sftp')
  File "/Library/Python/2.7/site-packages/paramiko/channel.py", line 235, in invoke_subsystem
    self._wait_for_event()
  File "/Library/Python/2.7/site-packages/paramiko/channel.py", line 1085, in _wait_for_event
    raise e
paramiko.ssh_exception.SSHException: Channel closed.

原因:因为服务器sftp的服务未开启

解决:

1.打开/etc/ssh/sshd_config 

2.加入下面的代码

Subsystem sftp /usr/lib/openssh/sftp-server

3.重启ssh服务

sudo /etc/init.d/ssh restart


你可能感兴趣的:(python)