网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 交易代码 > ASP.Net精品代码 > 正文

ftp操作实现类

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务

  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

  • 下一篇资讯: 数据库操作通类实现
  • 设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
    版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师