之前乐博网有发布过关于ftp上传下载的文章,相对目前要介绍的代码而言,过于繁杂;现在就开始看看简洁的实现方式吧 :)
首先介绍ftp下载,代码如下:
Const Str_FtpServer As String = "ftp://ftp.lob.cn"
Private Str_Username As String = "lob" Private Str_Password As String = "xxxxxxxx"
Private Sub DownloadFile(ByVal Str_Path As String) Try Dim Str_Filename As String = Str_Path Dim ftpReq As FtpWebRequest = WebRequest.Create(Str_Filename) ftpReq.Method = WebRequestMethods.Ftp.DownloadFile ftpReq.Credentials = New NetworkCredential(Str_Username, Str_Password) Dim FTPResp As FtpWebResponse = ftpReq.GetResponse Dim ftpRespStream As Stream = FTPResp.GetResponseStream 'FTPResp.StatusDescription 为回显状态的描述 可用于调试 ftpRespStream.Save("d:\lobdotcn.rar") '保存到本地的路径,如果你乐意也可以直接定义到参数中 FTPResp.Close() Catch ex As Exception MsgBox(ex.Message) End Try End Sub
调用方式:DownloadImage(Str_FtpServer& "/logo.jpg")
|