日期:2011-04-11 浏览次数:20370 次
‘在Visual Basic.NET 2002中进行调用。你会
‘将数据移动8位。在Visual Basic .NET 2002中,你必须
‘这个数乘以2的8次方
‘端口=parts(4)*(2^8)
‘进行调用,并且接着以Visual Basic .NET 2003进行注释当前行。
port = parts(4) << 8
Dim ftpClient As New clsFTP("localhost", "", "anonymous", "", 80)
If (ftpClient.Login() = True) Then
‘创建一个新文件夹
ftpClient.CreateDirectory("FTPFOLDERNEW")
‘将新的文件夹设置为活动文件夹。
ftpClient.ChangeDirectory("FTPFOLDERNEW")
‘设置FTP模式
ftpClient.SetBinaryMode(True)
‘从你的硬盘上上载一个文件到FTP网页
ftpClient.UploadFile(Server.MapPath("SampleFile.xml"))
‘对上载文件重命名
ftpClient.RenameFile("SampleFile.xml", "SampleFile_new.xml")
‘删除一个文件
ftpClient.DeleteFile("SampleFile_new.xml")
‘总是关闭链接,确保没有任何不在使用中的FTP链接
‘检查你是否登录到FTP服务器,并且接着关闭链接
ftpClient.CloseConnection()
End If
‘这个类允许你使用Visual Basic.NET对FTP网页执行直接链接。
‘这个类支持以下FTP命令:
‘-Upload 一个文件
‘-Download一个文件
‘-Create 一个目录
‘-Remove 一个目录
‘-改变目录
‘-Remove 一个文件
‘-Rename 一个文件
‘-Set 远程用户的用户名
‘-Set 远程用户的密码
Imports System
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Net.Sockets
‘FTP 类
Public Class clsFTP
#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
Private m_bLoggedIn As Boolean
Private m_sMes, m_sReply As String
‘设置用户来对FTP服务器读取和写入数据的数据包的大小
‘对下列具体大小
Public Const BLOCK_SIZE = 512
Private m_aBuffer(BLOCK_SIZE) As Byte
Private ASCII As Encoding = Encoding.ASCII
Public flag_bool As Boolean
‘普通变量定义
Private m_sMessageString As String
#End Region
#Region "Class Constructors"
‘Main类的构造器
Public Sub New()
m_sRemoteHost = "microsoft"
m_sRemotePath = "."
m_sRemoteUser = "anonymous"
m_sRemotePassword = ""
m_sMessageString = ""
m_iRemotePort = 21
m_bLoggedIn = False
End Sub
‘参数化的构造器
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 "Public Properties"
‘设置或得到你想链接的FTP服务器的名称
Public Property RemoteHostFTPServer() As String
‘得到FTP服务器的名称
Get
Return m_sRemoteHost
End Get
‘设置FTP服务器的名称
Set(ByVal Value As String)
m_sRemoteHost = Value
End Set
End Property