Archived Forum Post

Index of archived forum posts

Question:

No connection could be made because the target machine actively refused it.

Aug 23 '12 at 12:49

I am having Visual Studio 2008 .Net (.Net 2.0) and tried to secure FTP upload files in .Net Web application (C#).

I have downloaded trial version of chilkat for .Net .

For upload a file I have used the following code as given in your website also provided the proper FTP Server name, UserName and password.

Chilkat. SFtp sftp = new Chilkat.SFtp();

int port;
string hostname;
bool success = true;

//hostname = "www.my-ssh-server.com";
hostname = "123.111.123.111";
port = 22;

success = sftp.Connect(hostname, port);
if (success != true)
    {
    Response.Write(sftp.LastErrorText);
    }

But is shows the error "No connection could be made because the target machine actively refused it." Could you please clarify how to solve this issue. Say if my ftp server is (remote server where files to be uploaded) 123.111.123.111 and the folder is "FTPTesting" in the remote server and the file is C:/Test1.txt. Please let me know how to connect and upload the file to remote ftp server in secure FTP...


Answer

A good first step in solving this problem is to Google the error message: "No connection could be made because the target machine actively refused it."

Just cut-and-paste the entire error message into Google: "No connection could be made because the target machine actively refused it."

The 1st search result is this page: http://stackoverflow.com/questions/2972600/no-connection-could-be-made-because-the-target-machine-actively-refused-it

It says:

it literally means that the machine exists but that it has no services listening on the specified port, or there is a firewall stopping you.

If it happens occasionally - you used the word "sometimes" - and retrying succeeds, it is likely because the server has a full 'backlog'.

If it's not a firewall, then it means that no service is listening on port 22. Given the description of the problem, I'm suspecting you're confused about FTP vs SSH/SFTP. See this:

"SFTP" is the Secure File Transfer Protocol over SSH. It is a protocol unrelated to the FTP protocol. The Chilkat SSH / SFTP component is used for "SFTP". SFTP is achieved by connecting to an SSH server at port 22.

On the other hand, the Chilkat FTP2 component is for FTP. FTP servers listen at port 21 (non-SSL/TLS) and port 990 (SSL). FTP over SSL (i.e. port 990) is called "FTPS".

I suspect what you really need is the Chilkat FTP2 component for the FTP protocol, which is for port 21 (or port 990).