index2 = m_sReply.IndexOf(")")
ipData = m_sReply.Substring(index1 + 1, index2 - index1 - 1)
len = ipData.Length
partCount = 0
buf = ""
For i = 0 To ((len - 1) And partCount <= 6)
ch = Char.Parse(ipData.Substring(i, 1))
If (Char.IsDigit(ch)) Then
buf += ch
ElseIf (ch <> ",") Then
MessageString = m_sReply
Throw New IOException("Malformed PASV reply: " & m_sReply)
End If
If ((ch = ",") Or (i + 1 = len)) Then
Try
parts(partCount) = Int32.Parse(buf)
partCount += 1
buf = ""
Catch ex As Exception
MessageString = m_sReply
Throw New IOException("Malformed PASV reply: " & m_sReply)
End Try
End If
Next
ipAddress = parts(0) & "." & parts(1) & "." & parts(2) & "." & parts(3)
port = parts(4) << 8
' Determine the data port number.
port = port + parts(5)
s = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
ep = New IPEndPoint(Dns.Resolve(ipAddress).AddressList(0), port)
Try
s.Connect(ep)
Catch ex As Exception
MessageString = m_sReply
Throw New IOException("Cannot connect to remote server")
'If you cannot connect to the FTP
'server that is specified, make the boolean variable false.
flag_bool = False
End Try
'If you can connect to the FTP server that is specified, make the boolean variable true.
flag_bool = True
Return s
End Function
#End Region
End Class