Sammy
Sammy

Reputation: 41

Getting "socket.error: [Errno 61] Connection refused" python paramiko

Getting error connection refused error when trying to connect to the host to copy a local file to the host server. Don't have any issue connecting to the server remotely though.

host = "9.29.22.222"
 username = "XXX"
 password = "XXX"
 local_path = "/Users/samuelhii/Desktop/file.txt"
 remote_path = "C:\Program Files (x86)\file.txt"
 s = paramiko.SSHClient() 
 s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 s.connect(host,22,username,password)
 sftp = s.open_sftp()
 sftp.put(local_path,remote_path) 

Upvotes: 4

Views: 60255

Answers (1)

Klaus D.
Klaus D.

Reputation: 14369

The connection was refused by the server. This can be caused by several reasons not related to Python programming:

  • a firewall
  • the SSH service is configure not to take requests from your IP
  • bad host ip
  • … (many more)

Check if you can use the normal SSH client to connect with this host/user/password combination.

Upvotes: 6

Related Questions