If (Not (m_bLoggedIn)) Then
Login()
End If
'Send an FTP command to remove a folder on the FTP server.
SendCommand("RMD " & sDirName)
If (m_iRetValue <> 250) Then
bResult = False
MessageString = m_sReply
End If
' Return the final result.
Return bResult
End Function
'This is a function that is used to change the current working folder on the remote FTP server.
Public Function ChangeDirectory(ByVal sDirName As String) As Boolean
Dim bResult As Boolean
bResult = True
'Check if you are in the root directory.
If (sDirName.Equals(".")) Then
Exit Function
End If
'Check if you are logged on to the FTP server.
If (Not (m_bLoggedIn)) Then
Login()
End If
'Send an FTP command to change the folder on the FTP server.
SendCommand("CWD " & sDirName)
If (m_iRetValue <> 250) Then
bResult = False
MessageString = m_sReply
End If
Me.m_sRemotePath = sDirName
' Return the final result.
Return bResult
End Function
#End Region
#Region "FTP_QUIT"
' Close the FTP connection of the remote server.
Public Sub QUIT()
If (Not (m_objClientSocket Is Nothing)) Then
'Send an FTP command to end an FTP server system.
SendCommand("QUIT")
End If
Cleanup()
End Sub
#End Region
#Region "关闭FTP连接"
' Close the FTP connection of the remote server.
Public Sub CloseConnection()
If (Not (m_objClientSocket Is Nothing)) Then
'Send an FTP command to close an FTP server system.
SendCommand("Close")
End If
Cleanup()
End Sub
#End Region
#End Region
#Region "Private Subs and Functions"
' Read the reply from the FTP server.
Private Sub ReadReply()
m_sMes = ""
m_sReply = ReadLine()
m_iRetValue = Int32.Parse(m_sReply.Substring(0, 3))
End Sub
' Clean up some variables.
Private Sub Cleanup()
If Not (m_objClientSocket Is Nothing) Then
m_objClientSocket.Close()
m_objClientSocket = Nothing
End If
m_bLoggedIn = False
End Sub
' Read a line from the FTP server.
Private Function ReadLine(Optional ByVal bClearMes As Boolean = False) As String
Dim seperator As Char = ControlChars.Lf
Dim mess() As String
If (bClearMes) Then
m_sMes = ""
End If
Do While (True)
m_aBuffer.Clear(m_aBuffer, 0, BLOCK_SIZE)
m_iBytes = m_objClientSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)
m_sMes += ASCII.GetString(m_aBuffer, 0, m_iBytes)
If (m_iBytes < m_aBuffer.Length) Then
Exit Do
End If
Loop
mess = m_sMes.Split(seperator)
If (m_sMes.Length > 2) Then
m_sMes = mess(mess.Length - 2)
Else
m_sMes = mess(0)
End If
If (Not (m_sMes.Substring(3, 1).Equals(" "))) Then
Return ReadLine(True)
End If
Return m_sMes
End Function
' This is a function that is used to send a command to the FTP server that you are connected to.
Private Sub SendCommand(ByVal sCommand As String)
sCommand = sCommand & ControlChars.CrLf
Dim cmdbytes As Byte() = ASCII.GetBytes(sCommand)
m_objClientSocket.Send(cmdbytes, cmdbytes.Length, 0)
ReadReply()
End Sub
' Create a data socket.
Private Function CreateDataSocket() As Socket
Dim index1, index2, len As Int32
Dim partCount, i, port As Int32
Dim ipData, buf, ipAddress As String
Dim parts(6) As Int32
Dim ch As Char
Dim s As Socket
Dim ep As IPEndPoint
'Send an FTP command to use a passive data connection.
SendCommand("PASV")
If (m_iRetValue <> 227) Then
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If
index1 = m_sReply.IndexOf("(&quo