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

ftp操作实现类

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务
ception(m_sReply.Substring(4))

  End If

  'Check to see if the file exists before the upload.

  bFileNotFound = False

  If (File.Exists(sFileName)) Then

  ' Open the input stream to read the source file.

  input = New FileStream(sFileName, FileMode.Open)

  If (offset <> 0) Then

  input.Seek(offset, SeekOrigin.Begin)

  End If

  'Upload the file.

  m_iBytes = input.Read(m_aBuffer, 0, m_aBuffer.Length)

  Do While (m_iBytes > 0)

  cSocket.Send(m_aBuffer, m_iBytes, 0)

  m_iBytes = input.Read(m_aBuffer, 0, m_aBuffer.Length)

  Loop

  input.Close()

  Else

  bFileNotFound = True

  End If

  If (cSocket.Connected) Then

  cSocket.Close()

  End If

  'Check the return value if the file was not found.

  If (bFileNotFound) Then

  MessageString = m_sReply

  Throw New IOException("The file: " & sFileName & " was not found." & _

  " Cannot upload the file to the FTP site.")

  End If

  ReadReply()

  If (Not (m_iRetValue = 226 Or m_iRetValue = 250)) Then

  MessageString = m_sReply

  Throw New IOException(m_sReply.Substring(4))

  End If

  Finally

  If Not IsNothing(input) Then

  input.Close()

  End If

  If (cSocket.Connected) Then

  cSocket.Close()

  If (sFileName <> "") And (sFileName.IndexOf("\") <> -1) Then

  Dim index As String = sFileName.LastIndexOf("\")

  Dim TempFileName As String

  TempFileName = sFileName.Substring(index + 1, sFileName.Length - index - 1)

  DeleteFile(TempFileName)

  End If

  End If

  End Try

  End Sub

  #End Region

  #Region "FTP上的文件删除"

  ' Delete a file from the remote FTP server.

  Public Function DeleteFile(ByVal sFileName As String) As Boolean

  Dim bResult As Boolean

  bResult = True

  If (Not (m_bLoggedIn)) Then

  Login()

  End If

  'Send an FTP command to delete a file.

  SendCommand("DELE " & sFileName)

  If (m_iRetValue <> 250) Then

  bResult = False

  MessageString = m_sReply

  End If

  ' Return the final result.

  Return bResult

  End Function

  #End Region

  #Region "FTP上的文件重命名"

  ' Rename a file on the remote FTP server.

  Public Function RenameFile(ByVal sOldFileName As String, _

  ByVal sNewFileName As String) As Boolean

  Dim bResult As Boolean

  bResult = True

  If (Not (m_bLoggedIn)) Then

  Login()

  End If

  'Send an FTP command to rename a file.

  SendCommand("RNFR " & sOldFileName)

  If (m_iRetValue <> 350) Then

  MessageString = m_sReply

  Throw New IOException(m_sReply.Substring(4))

  End If

  'Send an FTP command to rename a file to a file name.

  'It will overwrite if newFileName exists.

  SendCommand("RNTO " & sNewFileName)

  If (m_iRetValue <> 250) Then

  MessageString = m_sReply

  Throw New IOException(m_sReply.Substring(4))

  End If

  ' Return the final result.

  Return bResult

  End Function

  #End Region

  #Region "FTP文件夹操作"

  'This is a function that is used to create a folder on the remote FTP server.

  Public Function CreateDirectory(ByVal sDirName As String) As Boolean

  Dim bResult As Boolean

  bResult = True

  If (Not (m_bLoggedIn)) Then

  Login()

  End If

  'Send an FTP command to make a folder on the FTP server.

  SendCommand("MKD " & sDirName)

  If (m_iRetValue <> 257) Then

  bResult = False

  MessageString = m_sReply

  End If

  ' Return the final result.

  Return bResult

  End Function

  ' This is a function that is used to delete a folder on the remote FTP server.

  Public Function RemoveDirectory(ByVal sDirName As String) As Boolean

  Dim bResult As Boolean

  bResult = True

  'Check if you are logged on to the FTP server.

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