zoukankan      html  css  js  c++  java
  • VB.Net实现Ftp上传的方法

    调用方式:

    UploadFile("d:\lob.rar", False) '  2个参数分别为 准备上传的文件完整路径、是否续传

    功能函数:

     Public Sub UploadFile(ByVal Str_LocalFileName As String, ByVal Bool_Resume As Boolean)

            Dim LobSocket As Socket
            Dim offset As Long
            Dim input As FileStream
            Dim bFileNotFound As Boolean
            If (Not Logined()) Then  
                Logined()
            End If
            LobSocket = CreateDataSocket()
            offset = 0
            If (Bool_Resume) Then
                Try
                    SetBinaryMode(True)
                    offset = GetFileSize(Str_LocalFileName)
                Catch ex As Exception
                    offset = 0
                End Try
            End If
            If (offset > 0) Then
                SendCommand("REST " & offset)
                If (Int_Reply <> 350) Then
                    offset = 0
                End If
            End If
            SendCommand("STOR " & Path.GetFileName(Str_LocalFileName))
            Str_Reply = ServerReply(True)
            Int_Reply = Int32.Parse(Str_Reply.Substring(0, 3))
            If (Not (Int_Reply = 125 Or Int_Reply = 150)) Then
                MsgBox(Str_Reply.Substring(4))
            End If
            bFileNotFound = False
            If (File.Exists(Str_LocalFileName)) Then
                input = New FileStream(Str_LocalFileName, FileMode.Open)
                If (offset <> 0) Then
                    input.Seek(offset, SeekOrigin.Begin)
                End If
                Int_Bytes = input.Read(Byte_Buffer, 0, Byte_Buffer.Length)
                Do While (Int_Bytes > 0)
                    LobSocket.Send(Byte_Buffer, Int_Bytes, 0)
                    Int_Bytes = input.Read(Byte_Buffer, 0, Byte_Buffer.Length)
                Loop
                input.Close()
            Else
                bFileNotFound = True
            End If
            If (LobSocket.Connected) Then
                LobSocket.Close()
            End If
            If (bFileNotFound) Then
                MsgBox(Str_LocalFileName & "文件未找到,无法上传")
            End If
            Str_Reply = ServerReply(True)
            Int_Reply = Int32.Parse(Str_Reply.Substring(0, 3))
            If (Not (Int_Reply = 226 Or Int_Reply = 250)) Then
                MsgBox(Str_Reply.Substring(4))
            End If

        End Sub

        Public Function GetFileSize(ByVal sFileName As String) As Long

            Dim size As Long
            SendCommand("SIZE " & sFileName)
            size = 0
            Str_Reply = ServerReply(True)
            Int_Reply = Int32.Parse(Str_Reply.Substring(0, 3))
            If (Int_Reply = 213) Then
                size = Int64.Parse(Str_Reply.Substring(4))
            Else
                MsgBox(Str_Reply.Substring(4))
            End If
            Return size

        End Function

  • 相关阅读:
    c
    罗扎诺夫高效记忆音乐【推荐试试】
    通过信息系统项目管理师最高可申领补贴2000元
    人事考试网【您有新信息】浙江人事考试网_浙江省公务员考试网_2017浙江公务员考试_中公浙江
    几种需求管理工具(转)_伊处_新浪博客
    PLM_百度百科
    统御软件 (oKit)| 项目管理软件,项目管理咨询,项目需求管理工具,集成研发管理平台 ——管理咨询与实施工具 一站式项目管理解决方案
    Oracle PLM
    Oracle PLM
    Oracle PLM
  • 原文地址:https://www.cnblogs.com/NetPig/p/2096802.html
Copyright © 2011-2022 走看看