zoukankan      html  css  js  c++  java
  • VB.NET FTP服务器上下载文件

    一个子程序是有关从FTP服务器上下载文件的。

    Sub getFileFromFTP(ByVal localFile As String, ByVal remoteFile As String, ByVal host As String, ByVal username As String, ByVal password As String)
            Dim URI As String = host & remoteFile
            Dim ftp As System.Net.FtpWebRequest = CType(FtpWebRequest.Create(URI), FtpWebRequest)

            ftp.Credentials = New System.Net.NetworkCredential(username, password)

            ftp.KeepAlive = False
            'we want a binary transfer, not textual data
            ftp.UseBinary = False

            'Define the action required (in this case, download a file)
            ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

            Using response As System.Net.FtpWebResponse = CType(ftp.GetResponse, System.Net.FtpWebResponse)
                Using responseStream As IO.Stream = response.GetResponseStream
                    'loop to read & write to file
                    Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
                        Dim buffer(2047) As Byte
                        Dim read As Integer = 0
                        Do
                            read = responseStream.Read(buffer, 0, buffer.Length)
                            fs.Write(buffer, 0, read)
                        Loop Until read = 0 'see Note(1)
                        responseStream.Close()
                        fs.Flush()
                        fs.Close()
                    End Using
                    responseStream.Close()
                End Using
                response.Close()
            End Using

        End Sub

  • 相关阅读:
    android 调试卡在:Waiting for Debugger
    将DataTable 数据插入 SQL SERVER 数据库
    android adb shell 命令大全
    GeoServer地图开发解决方案(四):发布Web地图服务(WMS)篇
    GeoServer地图开发解决方案(三):部署地图数据篇
    GeoServer地图开发解决方案(二):地图数据处理篇
    GeoServer地图开发解决方案(一):环境搭建篇
    pl/sql developer 导入sql脚本
    Myeclipse2013破解方法
    CentOS 6.4下架设NFS服务器
  • 原文地址:https://www.cnblogs.com/by1455/p/1086481.html
Copyright © 2011-2022 走看看