| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net应用技巧 >> 技术文摘正文
最新推荐 更多内容
VB.Net实现Ftp上传的方法[乐博网原创]
VB.Net实现Ftp上传的方法[乐博网原创]
作者:逍遥    来源:乐博网     更新时间:2011-2-18

本文需要您已经看过上期发布的 

VB.Net实现登陆Ftp的方法[乐博网原创] 

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

  • 上一篇:

  • 下一篇:
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    Serv-U密码加密原理并实现( ASP.NET基于C# )
    C#管理Serv-U6.4.0.6的方法
    VB.Net实现FTP编程的学习笔记.04.[乐博网]
    VB.Net实现FTP编程的学习笔记.03.[乐博网]
    VB.Net实现FTP编程的学习笔记.02.[乐博网]
    VB.Net实现FTP编程的学习笔记.01.[乐博网]
    VB.Net实现Ftp下载的方法[乐博网原创]
    VB.Net实现登陆Ftp的方法[乐博网原创]
    VB.Net实现FTP下载文件的两种方法

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]