WinSCP.SessionRemoteException: Network error: Connection to XXXX refused

Published: Aug 23, 2019
Post Author Written by eOne Solutions

I’m using the WinSCP application to connect to my SFTP server.

I can connect and upload/download files successfully when using the WinSCP application included in the download, but when I try to connect via SmartConnect scripting per this blog article, it fails with the error:

WinSCP error message
WinSCP.SessionRemoteException: Network error: Connection to “” refused.

Make sure that you are connecting to the correct port in your code.
In the code example, port 2222 is being used:

.PortNumber = 2222

Make sure to modify this to use the same port that you see the WinSCP application connect successfully.  Very often port 22 is the correct number but it can be any value the host system has set it to.

Feeling stuck? Get the support and guidance you need to help you power through any data challenge

We're on your integration team. Connect with our people and let us know how we can help you.