vb.netftp下载 vbs ftp 下载

VB6.0 FTP下载上传问题【可加分!】首先介绍ftp下载,代码如下: Const Str_FtpServer As String = " " 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. 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")==============================================================你先看看是你想要的不?是的话再往下看从这里copy过来的:呵呵我是做C#的,但是看你这分数实在太诱人,就帮你找了找~
记得采纳啊
vb.net中要从FTP服务器某一文件夹内下载如*.txt的文件,代码如何写Dim ftpclient As System.Net.FtpWebRequest = System.Net.FtpWebRequest.Create(New System.Uri("...
VBNET从FTP下载文件 , 需要先判断文件是否存在吗需要 。
在实际使用FTP文件服务器的过程中,经常需要远程下载解析文件 。为提高效率,需要判断文件存在与否,有选择的进行解析 。
FTP协议是一个用于在计算机网络上客户端和服务器之间进行文件传输的应用层协议 , 包括FTP服务器和FTP客户端两个组成部分 。FTP能操作任何类型的文件而不需要进一步处理 , 但有着极高的延时,从开始请求到第一次接收需求数据之间的时间较长,并不时地执行一些冗长的登录进程 。
vb.net FTP问题?If My.Computer.Network.IsAvailable Then
'如果可用
Else
'不可用
End If
Public Sub DownloadFile ( _
address As Uri, _
destinationFileName As String, _
userName As String, _
password As String, _
showUI As Boolean, _
connectionTimeout As Integer, _
overwrite As Boolean, _
onUserCancel As UICancelOption _
)
参数
address
String 或 Uri 。要下载的文件的路径,包括文件名和主机地址 。必选 。
destinationFileName
String 。下载文件的文件名和路径 。必选 。
userName
String 。要进行身份验证的用户名 。默认值为空字符串 "" 。
password
String 。要进行身份验证的密码 。默认值为空字符串 "" 。
showUI
Boolean 。指定是否显示操作进度 。默认为 False 。
connectionTimeout
Int32 。以毫秒为单位的超时间隔 。默认值为 100 秒 。
overwrite
Boolean 。指定是否改写现有文件 。默认为 False 。
onUserCancel
UICancelOption 。指定当用户在对话框(此对话框在 ShowUI 设置为 True 时显示)上单击“取消”或“否”时的行为 。默认为 ThrowException 。
用vb.net ftp文件下载My.Computer.Network.DownloadFile("", "D:\s.bat", "ftp账号", "ftp密码", True, 100, True)
VB.net连接FTP操作MSDN上的,看看对你有没有帮助 。GOOD LUCK!
Imports System.Net
Imports System.IO
Module FtpSample
Sub Main(ByVal args() As String)
If args.Length = 0 OrElse args(0).Equals("/?") Then
DisplayUsage()
ElseIf args.Length = 1 Then
Download(args(0))
ElseIf args.Length = 2 Then
If args(0).Equals("/list") Then
List(args(1))
Else
Upload(args(0), args(1))
End If
Else
Console.WriteLine("Unrecognized argument.")
End If
End Sub
Private Sub DisplayUsage()
Console.WriteLine("USAGE:")
Console.WriteLine("FtpSample [/? | FTP download URL | local file")
Console.WriteLine("FTP upload URL | /list FTP list URL]")
Console.WriteLine()
Console.WriteLine("where")
Console.WriteLine("FTP download URLURL of a file to download from an FTP server.")
Console.WriteLine("FTP upload URLLocation on a FTP server to upload a file to.")
Console.WriteLine("FTP list URLLocation on a FTP server to list the contents of.")
Console.WriteLine("local fileA local file to upload to an FTP server.")
Console.WriteLine()
Console.WriteLine("Options:")
Console.WriteLine("/?Display this help message.")
Console.WriteLine("/listSpecifies the list command.")
Console.WriteLine()
Console.WriteLine("EXAMPLES:")
Console.WriteLine("Download a fileFtpSample ")
Console.WriteLine("Upload a fileFtpSample upload.txt ")
End Sub
Private Sub Download(ByVal downloadUrl As String)
Dim responseStream As Stream = Nothing
Dim fileStream As FileStream = Nothing
Dim reader As StreamReader = Nothing
Try
Dim downloadRequest As FtpWebRequest = _
WebRequest.Create(downloadUrl)
Dim downloadResponse As FtpWebResponse = _
downloadRequest.GetResponse()
responseStream = downloadResponse.GetResponseStream()
Dim fileName As String = _
Path.GetFileName(downloadRequest.RequestUri.AbsolutePath)
If fileName.Length = 0 Then
reader = New StreamReader(responseStream)
Console.WriteLine(reader.ReadToEnd())
Else
fileStream = File.Create(fileName)
Dim buffer(1024) As Byte
Dim bytesRead As Integer
While True
bytesRead = responseStream.Read(buffer, 0, buffer.Length)
If bytesRead = 0 Then
Exit While
End If
fileStream.Write(buffer, 0, bytesRead)
End While
End If
Console.WriteLine("Download complete.")
Catch ex As UriFormatException
Console.WriteLine(ex.Message)
Catch ex As WebException
Console.WriteLine(ex.Message)
Catch ex As IOException
Console.WriteLine(ex.Message)
Finally
If reader IsNot Nothing Then
reader.Close()
ElseIf responseStream IsNot Nothing Then
responseStream.Close()
End If
If fileStream IsNot Nothing Then
fileStream.Close()
End If
End Try
End Sub
Private Sub Upload(ByVal fileName As String, ByVal uploadUrl As String)
Dim requestStream As Stream = Nothing
Dim fileStream As FileStream = Nothing
Dim uploadResponse As FtpWebResponse = Nothing
Try
Dim uploadRequest As FtpWebRequest = WebRequest.Create(uploadUrl)
uploadRequest.Method = WebRequestMethods.
' UploadFile is not supported through an Http proxy
' so we disable the proxy for this request.
uploadRequest.Proxy = Nothing
requestStream = uploadRequest.GetRequestStream()
fileStream = File.Open(fileName, FileMode.Open)
Dim buffer(1024) As Byte
Dim bytesRead As Integer
While True
bytesRead = fileStream.Read(buffer, 0, buffer.Length)
If bytesRead = 0 Then
Exit While
End If
requestStream.Write(buffer, 0, bytesRead)
End While
' The request stream must be closed before getting the response.
requestStream.Close()
uploadResponse = uploadRequest.GetResponse()
Console.WriteLine("Upload complete.")
Catch ex As UriFormatException
Console.WriteLine(ex.Message)
Catch ex As IOException
Console.WriteLine(ex.Message)
Catch ex As WebException
Console.WriteLine(ex.Message)
Finally
If uploadResponse IsNot Nothing Then
uploadResponse.Close()
End If
If fileStream IsNot Nothing Then
fileStream.Close()
End If
If requestStream IsNot Nothing Then
requestStream.Close()
End If
End Try
End Sub
Private Sub List(ByVal listUrl As String)
Dim reader As StreamReader = Nothing
Try
Dim listRequest As FtpWebRequest = WebRequest.Create(listUrl)
listRequest.Method = WebRequestMethods.
Dim listResponse As FtpWebResponse = listRequest.GetResponse()
reader = New StreamReader(listResponse.GetResponseStream())
Console.WriteLine(reader.ReadToEnd())
Console.WriteLine("List complete.")
Catch ex As UriFormatException
Console.WriteLine(ex.Message)
Catch ex As WebException
Console.WriteLine(ex.Message)
Finally
If reader IsNot Nothing Then
reader.Close()
End If
End Try
End Sub
End Module
可以通过设置 Credentials 属性来指定用于连接服务器的凭据,也可以将它们包含在传递给 Create 方法的 URI 的 UserInfo 部分中 。
从 FTP 服务器下载文件时,如果命令成功,所请求的文件的内容即在响应对象的流中 。通过调用 GetResponseStream 方法,可以访问此流 。
如果使用 FtpWebRequest 对象向服务器上载文件,则必须将文件内容写入请求流,请求流是通过调用 GetRequestStream 方法或其异步对应方法(BeginGetRequestStream 和 EndGetRequestStream 方法)获取的 。必须写入流并在发送请求之前关闭该流 。
请求是通过调用 GetResponse 方法或其异步对应方法(BeginGetResponse 和 EndGetResponse 方法)发送到服务器的 。请求的操作完成时 , 会返回一个 FtpWebResponse 对象 。FtpWebResponse 对象提供操作的状态以及从服务器下载的所有数据 。
【vb.netftp下载 vbs ftp 下载】关于vb.netftp下载和vbs ftp 下载的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读