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

ftp操作实现类

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务
If (Not (m_bLoggedIn)) Then

  Login()

  End If

  cSocket = CreateDataSocket()

  'Send an FTP command,

  SendCommand("NLST " & sMask)

  If (Not (m_iRetValue = 150 Or m_iRetValue = 125)) Then

  'output.Close()

  MessageString = m_sReply

  Throw New IOException(m_sReply.Substring(4))

  End If

  m_sMes = ""

  Do While (True)

  m_aBuffer.Clear(m_aBuffer, 0, m_aBuffer.Length)

  bytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)

  m_sMes += ASCII.GetString(m_aBuffer, 0, bytes)

  If (bytes < m_aBuffer.Length) Then

  Exit Do

  End If

  Loop

  mess = m_sMes.Split(seperator)

  For i = 0 To mess.Length - 1

  If mess(i) <> "" Then

  mess(i) = Microsoft.VisualBasic.Left(mess(i), Len(mess(i)) - 1)

  End If

  Next i

  cSocket.Close()

  ReadReply()

  If (m_iRetValue <> 226) Then

  MessageString = m_sReply

  Throw New IOException(m_sReply.Substring(4))

  End If

  Return mess

  End Function

  #End Region

  #Region "取得文件大小"

  ' Get the size of the file on the FTP server.

  Public Function GetFileSize(ByVal sFileName As String) As Long

  Dim size As Long

  If (Not (m_bLoggedIn)) Then

  Login()

  End If

  'Send an FTP command.

  SendCommand("SIZE " & sFileName)

  size = 0

  If (m_iRetValue = 213) Then

  size = Int64.Parse(m_sReply.Substring(4))

  Else

  MessageString = m_sReply

  Throw New IOException(m_sReply.Substring(4))

  End If

  Return size

  End Function

  #End Region

  #Region "FTP登录联结Log on"

  'Log on to the FTP server.

  Public Function Login() As Boolean

  m_objClientSocket = _

  New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

  Dim ep As New IPEndPoint(Dns.Resolve(m_sRemoteHost).AddressList(0), m_iRemotePort)

  Try

  m_objClientSocket.Connect(ep)

  Catch ex As Exception

  MessageString = m_sReply

  Throw New IOException("Cannot connect to remote server")

  End Try

  ReadReply()

  If (m_iRetValue <> 220) Then

  CloseConnection()

  MessageString = m_sReply

  Throw New IOException(m_sReply.Substring(4))

  End If

  'Send an FTP command to send a user logon ID to the server.

  SendCommand("USER " & m_sRemoteUser)

  If (Not (m_iRetValue = 331 Or m_iRetValue = 230)) Then

  Cleanup()

  MessageString = m_sReply

  Throw New IOException(m_sReply.Substring(4))

  End If

  If (m_iRetValue <> 230) Then

  'Send an FTP command to send a user logon password to the server.

  SendCommand("PASS " & m_sRemotePassword)

  If (Not (m_iRetValue = 230 Or m_iRetValue = 202)) Then

  Cleanup()

  MessageString = m_sReply

  Throw New IOException(m_sReply.Substring(4))

  End If

  End If

  m_bLoggedIn = True

  'Call the ChangeDirectory user-defined function to change the folder to the

  'remote FTP folder that is mapped.

  ChangeDirectory(m_sRemotePath)

  'Return the final result.

  Return m_bLoggedIn

  End Function

  #End Region

  #Region "BinaryMode"

  'If the value of mode is true, set the binary mode for downloads. Otherwise, set ASCII mode.

  Public Sub SetBinaryMode(ByVal bMode As Boolean)

  If (bMode) Then

  'Send the FTP command to set the binary mode.

  '(TYPE is an FTP command that is used to specify representation type.)

  SendCommand("TYPE I")

  Else

  'Send the FTP command to set ASCII mode.

  '(TYPE is a FTP command that is used to specify representation type.)

  SendCommand("TYPE A")

  End If

  If (m_iRetValue <> 200) Then

  MessageString = m_sReply

  Throw New IOException(m_sReply.Substring(4))

  End If

  End Sub

  #End Region

  #Region "FTP文件下载"

  ' Download a file to the local folder of the a

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