Question Unable to connect to the remote server (ConnectFailure)

Programgod

Member
Joined
May 4, 2011
Messages
17
Programming Experience
5-10
I have a rather interesting issue going on with an application that I developed several months ago for the company that I work for. My app goes out to an FTP site and downloads the latest data files then extracts them and imports them into a database. Up until recently the program was working perfectly, but as of a month ago (at least I am assuming based on the dates the files were downloaded last) the FTP connection is failing. I am getting the exception:

Message: Unable to connect to the remote server
Status: ConnectFailure
InnerException: NULL (this is one of the things that bothers me cause it is so vague as to what is actually causing the problem).

I have tried several things such as changing UseBinary, UsePassive, KeepAlive and specifying the port number and connecting by IP versus the FQDN. Nothing is working. And it is not just the site I am trying, it doesn't work with any FTP site I try. Now here is where things get interesting. I AM able to connect to the FTP site via DOS Prompt FTP as well as IE browser. So I know that the site is up and that the firewall/proxy is not blocking connection to it. The other intesting thing is that I wrote up a quick FTP program on my home computer and was able to connect that way. (The only difference between my work computer and home computer is that I am running Win7 at home and WinXP at work, plus the hardware differences but that shouldn't make a difference.) I have also tested attempting to connect using my work computer from outside my workplace network, and it still fails. So the issue is definitely something on my computer, but for the life of me I can not figure out what it is. I have also tried uninstalling all recently automatic updates to the computer, still with no positive results.
:mad::mad::mad:

Sorry for the novel, but I have been working on this problem for the last couple of days and I am just at my wits end. I have scowered the web looking for a solution or someone that has had the same issue, but with no luck. If anyone can help me I would be incredibly greatful.

Here is my code:
VB.NET:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Net
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] 
Public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Form1
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]  Public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ftp [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] FtpWebRequest
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE][/COLOR][/SIZE] 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]  Private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] btnConnect_Click([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] btnConnect.Click
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]    Try
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]      ftp = FtpWebRequest.Create(txtSite.Text)
      [URL="ftp://ftp.Credentials"]ftp.Credentials[/URL] = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] NetworkCredential(txtUserID.Text, txtPassword.Text)
      [URL="ftp://ftp.KeepAlive"]ftp.KeepAlive[/URL] = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]      [URL="ftp://ftp.UseBinary"]ftp.UseBinary[/URL] = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]      [URL="ftp://ftp.Method"]ftp.Method[/URL] = WebRequestMethods.Ftp.ListDirectory
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE][/COLOR][/SIZE] 
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]      [B][U][COLOR=red]Using[/COLOR][/U][/B][/COLOR][/SIZE][/COLOR][/SIZE][B][U][COLOR=red][SIZE=2] resp [/SIZE][SIZE=2][SIZE=2]As[/SIZE][/SIZE][/COLOR][/U][/B][SIZE=2][B][U][COLOR=red] WebResponse = [URL="ftp://ftp.GetResponse"]ftp.GetResponse[/URL]()   <--- This is where the error occurrs[/COLOR][/U][/B]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]        Using[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] strm [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] IO.Stream = resp.GetResponseStream
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]          Using[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sread [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] IO.StreamReader = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] IO.StreamReader(strm)
            txtResponse.Text = sread.ReadToEnd
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]          End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Using
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]        End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Using
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]      End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Using
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]    Catch[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] wex [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] WebException
      txtResponse.Text = wex.Message
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]    End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]  End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub
End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Class
[/COLOR][/SIZE][/COLOR][/SIZE]
 
Last edited:
I just realized that the code I pasted in here was in CSharp. If need be I can post the VB.Net version of my code. I tried changing up the language to see if that would make any difference (I dont know why it would, I just figured I would try it... grasping at straws).
 
You should post VB.Net code here at VB.Net Forums if the code is relevant, you can also try C# Developer Forums for C# help.
I AM able to connect to the FTP site via DOS Prompt FTP as well as IE browser. So I know that the site is up and that the firewall/proxy is not blocking connection to it.
This tells you the server is up, and that your connection settings is correct, and that those applications are not blocked by a firewall. It could be an indication that your application is still blocked by a firewall.
 
Ok, I brought my work laptop home so I could try it again while I am not behind my work firewall/proxy. I am still getting the same error. I am almost positive is it something to do with the computer, but I just can't seem to figure out what. My company disables the Windows Firewall, but even still I put the ports and the application itself in the exception list just to make sure. I even opened the ports on my router to see if that was an issue, even though I am able to connect from my home computer without doing all that.
 
**SOLVED**

JohnH,

I would like to thank you for your suggestion. While it wasn't the firewall that was causing the issue, you did point me in the right direction. You got me thinking about computer policies and programs that could be blocking it. I finally figured out that it was McAfee Access Protection that was blocking my connections. While my company maintains that it has always blocked all FTP communication through McAfee, it was working up until last month. All I needed to do was have them add the executable name to the exclusion list and all is working fine now.

Thanks,
ProgramGod
 
I don't know McAfee but "Access Protection" does sound as a firewall feature or related to it. Glad you sorted it out.
 
Back
Top