Get Connection Status

Posted on 2014-11-26
Last Modified: 2014-11-27
How do you check connection status using .Net Framework 4.5?

Here's what I have:

Imports System.Net

Public Class FTPPlus2
   Shared Property HostName As String
   Shared Property Password As String
   Shared Property UserID As String
   Shared Property Target As String
   Shared Property ID As String
   Shared Property SiteName As String

   Shared Property request As FtpWebRequest
   Shared Property response As FtpWebResponse

   Shared Sub Disconnect()
      If response IsNot Nothing Then
      End If
   End Sub

   Shared Sub Connect()
      request = DirectCast(WebRequest.Create(String.Format("ftp://{0}", HostName)), FtpWebRequest)
   End Sub

   Shared Sub ChangeCurrentFolder(FolderName)

   End Sub

   Shared Function Connected As Boolean
      Dim ret As Boolean  = False

      Return ret
   End Function

   Shared Sub Login()
      request.Credentials = New NetworkCredential(UserID, Password)
   End Sub
End Class

Open in new window

Question by:Ray Turner
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40466990
If con.State = con.Open Then
	Connected  = true
	Connected  = false
End If

Open in new window


Expert Comment

ID: 40467072
Are you trying to determine if you can connect to the internet?
If so, you can do something like this.  I've used this in various apps and it works well.
You can use any url you want, but I just use google.

using the System.Net.WebClient

public static bool CheckForInternetConnection()
        using (var client = new WebClient())
        using (var stream = client.OpenRead(""))
            return true;
        return false;

Expert Comment

ID: 40467078
Sorry, here is version :).

Public Shared Function CheckForInternetConnection() As Boolean
            Using client = New WebClient()
                  Using stream = client.OpenRead("")
                        Return True
                  End Using
            End Using
            Return False
      End Try
End Function
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.


Author Comment

by:Ray Turner
ID: 40467291
I'm trying to determine the status of the FtpWebRequest.  Is there a way to determine if the connection is open/successful?
LVL 75

Accepted Solution

käµfm³d   👽 earned 500 total points
ID: 40467496
Catch the WebExceptions that GetRequestStream and GetResponse could throw.

Author Closing Comment

by:Ray Turner
ID: 40469955

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: (…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now