资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb点虐 访问ftp vbnet http服务器

VB点虐 连接FTP操作

MSDN上的,看看对你有没有帮助。GOOD LUCK!

创新互联建站为客户提供专业的成都网站建设、成都网站设计、程序、域名、空间一条龙服务,提供基于WEB的系统开发. 服务项目涵盖了网页设计、网站程序开发、WEB系统开发、微信二次开发、手机网站制作设计等网站方面业务。

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 URL URL of a file to download from an FTP server.")

Console.WriteLine(" FTP upload URL Location on a FTP server to upload a file to.")

Console.WriteLine(" FTP list URL Location on a FTP server to list the contents of.")

Console.WriteLine(" local file A local file to upload to an FTP server.")

Console.WriteLine()

Console.WriteLine(" Options:")

Console.WriteLine(" /? Display this help message.")

Console.WriteLine(" /list Specifies the list command.")

Console.WriteLine()

Console.WriteLine("EXAMPLES:")

Console.WriteLine(" Download a file FtpSample ")

Console.WriteLine(" Upload a file FtpSample 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点虐 2008如何操作FTP服务器?比如登录并保持登录状态,然后遍历根目录及指定的目录,以获

具体方法如下:”、打开Serv-U的配置管理界面puzb在“全局用户”或者“域用户”中选择“创建cgko修改和删除用户帐户”; 2、在“创建,修改和删除用户帐户”的界面,选择“添加”。;3、在“用户属性“对话框,“用户信息”下的用户名为:Anonymous,密码为空,为其指定FTP的根目录。 4、然后在“目录访问“选项,点击“添加”,为其指定访问权限和目录。 5、最后点击“保存”6这样我们就成功添加了匿名用户。

ftp上传文件用vb点虐 怎么实现

My.Computer.Network.UploadFile(本地文件路径, ftp服务器路径包括文件名,用户名,密码)

跪求VB.NET 连接FTP

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 URL URL of a file to download from an FTP server.")

Console.WriteLine(" FTP upload URL Location on a FTP server to upload a file to.")

Console.WriteLine(" FTP list URL Location on a FTP server to list the contents of.")

Console.WriteLine(" local file A local file to upload to an FTP server.")

Console.WriteLine()

Console.WriteLine(" Options:")

Console.WriteLine(" /? Display this help message.")

Console.WriteLine(" /list Specifies the list command.")

Console.WriteLine()

Console.WriteLine("EXAMPLES:")

Console.WriteLine(" Download a file FtpSample ")

Console.WriteLine(" Upload a file FtpSample 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点虐 访问ftp vbnet http服务器
分享路径:http://cdkjz.cn/article/ddjeice.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220