implementing ftp through webrequest.create

i am trying to implement ftp through the webrequest functionality. previously i got the error 'uri prefix not recognized'. i copied some code from http://support.microsoft.com/default.aspx scid=kb%3Ben-us%3B812404 but now i get another error. it is the object reference error and i understand why it is happening but i dont know what to put in the

Public Overrides Function GetResponse() As WebResponse

'Override

End Function

'Override section

CAN ANYONE HELP

Imports System.Net

Imports System.IO

Imports System.Net.Sockets

Public Class NetworkCommunication

Dim pResponseIdentifier As String

Dim pIPAddress As IPAddress

Dim pTimeOut As Integer

#Region "Properties"

Public ReadOnly Property ResponseIdentifier() As String

Get

ResponseIdentifier = pResponseIdentifier

End Get

End Property

Public WriteOnly Property SetResponseIdentifier() As String

Set(ByVal Value As String)

pResponseIdentifier = Value

End Set

End Property

Public Property IPAddress() As IPAddress

Get

IPAddress = pIPAddress

End Get

Set(ByVal Value As IPAddress)

pIPAddress = Value

End Set

End Property

Public Property TimeOut() As Integer

Get

TimeOut = pTimeOut

End Get

Set(ByVal Value As Integer)

pTimeOut = Value

End Set

End Property

#End Region

#Region "Enums"

Public Enum ResponseMode

Any = 0

Specific = 1

End Enum

#End Region

Public Class FtpWebRequest

Inherits WebRequest

Public Overrides Property Method() As String

Get

'Override

End Get

Set(ByVal Value As String)

'Override

End Set

End Property

Public Overrides Property Credentials() As ICredentials

Get

'Override

End Get

Set(ByVal Value As ICredentials)

'Override

End Set

End Property

Public Overrides Property ConnectionGroupName() As String

Get

'Override

End Get

Set(ByVal Value As String)

'Override

End Set

End Property

Public Overrides Property ContentLength() As Long

Get

'Override

End Get

Set(ByVal Value As Long)

'Override

End Set

End Property

Public Overrides Property ContentType() As String

Get

'Override

End Get

Set(ByVal Value As String)

'Override

End Set

End Property

Public Overrides Property Proxy() As IWebProxy

Get

'Override

End Get

Set(ByVal Value As IWebProxy)

'Override

End Set

End Property

Public Overrides Function GetRequestStream() As Stream

'Override

End Function

Public Overrides Function GetResponse() As WebResponse

'Override

End Function

End Class

Public Class FtpRequestCreator

Implements IWebRequestCreate

Public Sub New()

End Sub

Public Overridable Function Create(ByVal Url As Uri) As WebRequest Implements IWebRequestCreate.Create

Return New FtpWebRequest

End Function

End Class

Public Class FtpWebResponse

Inherits WebResponse

Public Overrides Property ContentType() As String

Get

'Override

End Get

Set(ByVal Value As String)

'Override

End Set

End Property

Public Overrides Function GetResponseStream() As Stream

'Override

End Function

End Class

#Region "Functions"

Public Function PingHost(ByVal Mode As ResponseMode) As Boolean

Dim Creator As FtpRequestCreator = New FtpRequestCreator

WebRequest.RegisterPrefix("ftp:", Creator)

'Dim ping As WebRequest = WebRequest.Create("http://" + IPAddress.ToString)

Dim ping As WebRequest = WebRequest.Create("ftp://" + IPAddress.ToString)

Try

If Mode = ResponseMode.Specific Then

Dim pingresult As WebResponse = ping.GetResponse()

If pingresult.ResponseUri.ToString.ToLower = "ftp://" + IPAddress.ToString + ResponseIdentifier Then

Return True

End If

Else

Dim pingresult As WebResponse = ping.GetResponse()

If pingresult.ResponseUri.ToString.StartsWith("ftp://" + IPAddress.ToString) Then

Return True

End If

End If

Catch ex As Exception

Return False

End Try

End Function

#End Region

End Class



Answer this question

implementing ftp through webrequest.create

  • worldhello

    Did you download and install the sample Because I think that the sample that you install actually contains the code inside, say, GetResponse(), but on the web page, to keep the web page short, it just showed the methods, and not the body.

  • Mar_GP

    yeah i downloaded the sample and got it working. thanks
  • implementing ftp through webrequest.create