当前位置:首页 > 服务器 > 正文

vb.net访问服务器(vb搭建服务器)

今天给各位分享vb.net访问服务器的知识,其中也会对vb搭建服务器进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

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 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.net如何访问服务器上的数据库

用ADO接口就可以,TCP/IP协议,设定数据库服务器的IP地址,数据库名,用户名,密码就可以连接。

如何在客户端访问服务器端的sql数据库(VB.NET)

通过企业管理器! 客户端安装和服务器对应版本的数据库 是SQL2000就装2000

2005 就装2005

如何跨区域解决VB.NET连接SQL2008服务器!

1、局域网的其他电脑是可以连接你的电脑上的sql2008的,就是用的你的电脑在局域网的主机名或IP地址(如192.168.0.101),其他跟你电脑的连接方式是没有任何差别的。

2、花生壳可以把你电脑的外网IP地址与一个固定的域名(可以是自己注册的域名,也可以是花生壳免费分配的二级或三级域名)进行绑定,然后其他地方的电脑通过这个域名就可以访问你电脑上的sql2008了。当然,你所在局域网连接外网的路由器应该把你电脑的内网IP地址以及端口号开放权限,这样路由器就会把外网的访问请求转发到你的电脑上了。

3、最好的解决办法,就是在网上购买一个sql服务器(比如阿里云、百度云、腾讯云这些“云们”提供的云数据服务器),这样全世界的任何电脑都可以连接你的数据库(当然必须知道登录信息才行)。这些业界大佬提供的服务器不管主机性能还是网络带宽以及服务的稳定性,都远远超过你用个人电脑架设的服务器。而且这样还能实现程序与数据的分离,简化程序的开发难度。你所说的用友、航天开票等几乎所有大范围使用的软件,基本上都是这样实现的。此外,还可以做成网页应用程序,这样就连软件都不需要了,直接用浏览器打开指定网页就能使用,这才是现在最流行的方式。

vb.net中关于 socket的连接服务器失败问题! 怎么处理连接失败?

用 try-catch 结构,捕获 SocketException,示例:

Try

    // 可能产生错误的代码

Catch ex As SocketException

    MessageBox.Show("连接失败,原因是:"  ex.Message)

End Try

P.S. 好久不写 VB.NET 的了,这个是根据 C# 和记忆中的样子写的,题主看明白思路就好。

vb.net 怎么样访问access数据库?

VB.NET使用OLEDB连接数据库,即可进行操作了。

但是不推荐使用ACCESS数据库,这个已经淘汰了。

VB.NET连接数据库,从性能上来说,官方推荐使用的是SQL SERVER 2005

vb.net访问服务器的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vb搭建服务器、vb.net访问服务器的信息别忘了在本站进行查找喔。

取消
扫码支持 支付码