Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 589
Bloomstar Avatar asked Sep 03 '26 12:09

Bloomstar


2 Answers

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")
like image 138
FunkySayu Avatar answered Sep 06 '26 01:09

FunkySayu


Try this:

vim /etc/ssh/sshd_config

uncomment this line:

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

Good luck!

like image 21
yong Avatar answered Sep 06 '26 02:09

yong