4

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) 
Imran Ali Khan
  • 8,469
  • 16
  • 52
  • 77
Sammy
  • 41
  • 1
  • 1
  • 2

1 Answers1

5

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.

Klaus D.
  • 13,874
  • 5
  • 41
  • 48
  • 4
    The simplest explanation is that there's no service listening for connections on port 22 of the remote server. Ie, there's no SSH server running, or it's listening on a different port. – Kenster Mar 17 '15 at 11:21