Bloomstar
Bloomstar

Reputation: 155

python paramiko SSHException: Channel closed

Im trying to establish a sftp connection to remote ubuntu machine.I was able to establish ssh connection.but it throws me an exception at open_sftp()

import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=hostname,port=port,username=username,password=password)
sftp = ssh.open_sftp()

paramiko.SSHException: Channel closed

can anyone help me.thanks in advance.

Upvotes: 3

Views: 11883

Answers (3)

Ground Stop
Ground Stop

Reputation: 36

On remote operating systems other than Ubuntu, the commented line listed in yong's solution may not exist. In this case, you may be able to fix the problem by adding the line to the file with the path modified to point to the correct location for your remote system's sftp-server.

On QNX, I was able to resolve this issue by modifying the /etc/ssh/sshd_config file and adding in the line:

Subsystem     sftp    /usr/libexec/sftp-server

Although the formatting for that line seemed out of place compared to the rest of the file, it still proved to be a successful solution as I was able to successfully open an SFTP client from an SSH client object without generating an SSHException.

Upvotes: 1

yong
yong

Reputation: 71

Try this:

vim /etc/ssh/sshd_config

uncomment this line:

# Subsystem     sftp    /usr/libexec/openssh/sftp-server

Good luck!

Upvotes: 1

FunkySayu
FunkySayu

Reputation: 8061

The last time I used SFTP with Paramiko, I also had some issues. I searched a bit on the web and i found this tool : https://github.com/jbardin/scp.py

To use it :

from scp import SCPClient
import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=hostname,port=port,username=username,password=password)

scpclient = SCPClient(ssh.get_transport(), socket_timeout=15.0)
scpclient.put("my_local_path", "my_remote_path")

Upvotes: 3

Related Questions