Imports System
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Net.Sockets
Public Class CMyFTP
#Region "Class Variable Declarations"
Private m_sRemoteHost, m_sRemotePath, m_sRemoteUser As String
Private m_sRemotePassword, m_sMess As String
Private m_iRemotePort, m_iBytes As Int32
Private m_objClientSocket As Socket
Private m_iRetValue As Int32
Public m_bLoggedIn As Boolean
Private m_sMes, m_sReply As String
'Set the size of the packet that is used to read and to write data to the FTP server
'to the following specified size.
Public Const BLOCK_SIZE = 512
Private m_aBuffer(BLOCK_SIZE) As Byte
Private ASCII As Encoding = Encoding.ASCII
Public flag_bool As Boolean
'General variable declaration
Private m_sMessageString As String
#End Region
#Region "Class Constructors"
'创建ftp对象
Public Sub New()
m_sRemoteHost = "127.0.0.1"
m_sRemotePath = "."
m_sRemoteUser = "ftpuser"
m_sRemotePassword = "ftppass"
m_sMessageString = ""
m_iRemotePort = 21
m_bLoggedIn = False
End Sub
' Parameterized constructor
Public Sub New(ByVal sRemoteHost As String, _
ByVal sRemotePath As String, _
ByVal sRemoteUser As String, _
ByVal sRemotePassword As String, _
ByVal iRemotePort As Int32)
m_sRemoteHost = sRemoteHost
m_sRemotePath = sRemotePath
m_sRemoteUser = sRemoteUser
m_sRemotePassword = sRemotePassword
m_sMessageString = ""
m_iRemotePort = 21
m_bLoggedIn = False
End Sub
#End Region
#Region "FTP连接相关设置 "
'Set or Get the name of the FTP server that you want to connect.
Public Property RemoteHostFTPServer() As String
'Get the name of the FTP server.
Get
Return m_sRemoteHost
End Get
'Set the name of the FTP server.
Set(ByVal Value As String)
m_sRemoteHost = Value
End Set
End Property
'Set or Get the FTP Port Number of the FTP server that you want to connect.
Public Property RemotePort() As Int32
'Get the FTP Port Number.
Get
Return m_iRemotePort
End Get
'Set the FTP Port Number.
Set(ByVal Value As Int32)
m_iRemotePort = Value
End Set
End Property
'Set or Get the remote path of the FTP server that you want to connect.
Public Property RemotePath() As String
'Get the remote path.
Get
Return m_sRemotePath
End Get
'Set the remote path.
Set(ByVal Value As String)
m_sRemotePath = Value
End Set
End Property
'Set or Get the remote password of the FTP server that you want to connect.
Public Property RemotePassword() As String
Get
Return m_sRemotePassword
End Get
Set(ByVal Value As String)
m_sRemotePassword = Value
End Set
End Property
'Set or Get the remote user of the FTP server that you want to connect.
Public Property RemoteUser() As String
Get
Return m_sRemoteUser
End Get
Set(ByVal Value As String)
m_sRemoteUser = Value
End Set
End Property
'Set the class MessageString.
Public Property MessageString() As String
Get
Return m_sMessageString
End Get
Set(ByVal Value As String)
m_sMessageString = Value
End Set
End Property
#End Region
#Region "Public Subs and Functions"
#Region "获取FTP服务器中指定目录的所有文件名"
'Return a list of files in a string() array from the file system.
Public Function GetFileList(ByVal sMask As String) As String()
Dim cSocket As Socket
Dim bytes As Int32
Dim seperator As Char = ControlChars.Lf
Dim mess() As String
Dim i As Integer = 0
m_sMes = ""
'Check if you are logged on to the FTP server.