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

ftp操作实现类

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务
ssembly, and keep the same file name.

  Public Sub DownloadFile(ByVal sFileName As String)

  DownloadFile(sFileName, "", False)

  End Sub

  ' Download a remote file to the local folder of the assembly, and keep the same file name.

  Public Sub DownloadFile(ByVal sFileName As String, _

  ByVal bResume As Boolean)

  DownloadFile(sFileName, "", bResume)

  End Sub

  'Download a remote file to a local file name. You must include a path.

  'The local file name will be created or will be overwritten, but the path must exist.

  Public Sub DownloadFile(ByVal sFileName As String, _

  ByVal sLocalFileName As String)

  DownloadFile(sFileName, sLocalFileName, False)

  End Sub

  ' Download a remote file to a local file name and include a path. Then, set the

  ' resume flag. The local file name will be created or will be overwritten, but the path must exist.

  Public Sub DownloadFile(ByVal sFileName As String, _

  ByVal sLocalFileName As String, _

  ByVal bResume As Boolean)

  Dim st As Stream

  Dim output As FileStream

  Dim cSocket As Socket

  Dim offset, npos As Long

  If (Not (m_bLoggedIn)) Then

  Login()

  End If

  SetBinaryMode(True)

  If (sLocalFileName.Equals("")) Then

  sLocalFileName = sFileName

  End If

  If (Not (File.Exists(sLocalFileName))) Then

  st = File.Create(sLocalFileName)

  st.Close()

  End If

  output = New FileStream(sLocalFileName, FileMode.Open)

  cSocket = CreateDataSocket()

  offset = 0

  If (bResume) Then

  offset = output.Length

  If (offset > 0) Then

  'Send an FTP command to restart.

  SendCommand("REST " & offset)

  If (m_iRetValue <> 350) Then

  offset = 0

  End If

  End If

  If (offset > 0) Then

  npos = output.Seek(offset, SeekOrigin.Begin)

  End If

  End If

  'Send an FTP command to retrieve a file.

  SendCommand("RETR " & sFileName)

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

  output.Close()

  MessageString = m_sReply

  Throw New IOException(m_sReply.Substring(4))

  End If

  Do While (True)

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

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

  output.Write(m_aBuffer, 0, m_iBytes)

  If (m_iBytes <= 0) Then

  Exit Do

  End If

  Loop

  output.Close()

  If (cSocket.Connected) Then

  cSocket.Close()

  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

  End Sub

  #End Region

  #Region "FTP文件上传"

  ' This is a function that is used to upload a file from your local hard disk to your FTP site.

  Public Sub UploadFile(ByVal sFileName As String)

  UploadFile(sFileName, False)

  End Sub

  ' This is a function that is used to upload a file from your local hard disk to your FTP site

  ' and then set the resume flag.

  Public Sub UploadFile(ByVal sFileName As String, _

  ByVal bResume As Boolean)

  Dim cSocket As Socket

  Dim offset As Long

  Dim input As FileStream

  Dim bFileNotFound As Boolean

  If (Not (m_bLoggedIn)) Then

  Login()

  End If

  cSocket = CreateDataSocket()

  offset = 0

  Try

  If (bResume) Then

  Try

  SetBinaryMode(True)

  offset = GetFileSize(sFileName)

  Catch ex As Exception

  offset = 0

  End Try

  End If

  If (offset > 0) Then

  SendCommand("REST " & offset)

  If (m_iRetValue <> 350) Then

  'The remote server may not support resuming.

  offset = 0

  End If

  End If

  'Send an FTP command to store a file.

  SendCommand("STOR " & Path.GetFileName(sFileName))

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

  MessageString = m_sReply

  Throw New IOEx

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