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操作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)
推荐阅读
- 电脑下载什么软件写字,电脑上用来写字的软件
- 用手机u盘怎么下载视频,用手机u盘怎么下载视频到电脑
- 无人直播怎么加帧率,无人直播间怎么弄
- vb.net图片转文字 vb导入图片的代码
- 先安装net后安装iis,先安装net framework 40
- 扑克麻将游戏软件开发费用,麻将开发软件公司
- 毕业设计网站密码怎么找回,毕业设计查找网站
- sap新形象短视频,sap产品介绍
- ios更新软件显示账号被限制,苹果更新app限制