标题:vb2005 关于FTP下载问题
只看楼主
qlong0728
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:272
专家分:0
注 册:2007-6-15
结帖率:100%
 问题点数:0 回复次数:2 
vb2005 关于FTP下载问题
在VB2005,请问你们是用什么控件做FTP下载的呢?

比如,用代码在指定的服务器里下载指定的文件到本地电脑上.
搜索更多相关主题的帖子: FTP 服务器 下载 控件 
2007-07-12 14:31
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
得分:0 
放个按钮.点击时链接文件的地址就可以实现的..不过这样不安全,呵呵

飘过~~
2007-07-12 17:02
taick
Rank: 1
等 级:新手上路
威 望:1
帖 子:71
专家分:0
注 册:2007-7-16
得分:0 

客户端:
Imports System.IO

Public Class frmMain
Inherits System.Windows.Forms.Form

Private Sub btn_Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Send.Click
If Not File.Exists(txt_FileName.Text) Then
MsgBox("找不到文件")
Exit Sub
End If
Try
Dim sendsocket As New Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
''实例化socket
Dim ipendpiont As New Net.IPEndPoint(Net.IPAddress.Parse("192.168.106.123"), 8888) ''建立终结点
''OpenFileDialog1.ShowDialog()
Dim fs As New IO.FileStream(txt_FileName.Text, IO.FileMode.OpenOrCreate, IO.FileAccess.Read) ''要传输的文件
Dim fssize(fs.Length - 1) As Byte
Dim strread As New IO.BinaryReader(fs) ''流处理要传输的文件
''fs.Read(fssize, 0, fssize.Length - 1)
strread.Read(fssize, 0, fssize.Length - 1)
sendsocket.Connect(ipendpiont) ''连接远程计算机
sendsocket.Send(fssize) ''发送文件
Label1.Text = fs.Length()
fs.Close()
sendsocket.Shutdown(Net.Sockets.SocketShutdown.Send)
''关闭发送连接
sendsocket.Close() ''关闭本机socket
Catch ex As Exception
End Try
End Sub

Private Sub btn_Open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Open.Click
If ofd_Open.ShowDialog = Windows.Forms.DialogResult.OK Then
txt_FileName.Text = ofd_Open.FileName
End If
End Sub
End Class

服务器:
Public Class frmMain
Inherits System.Windows.Forms.Form
Dim receivesocket As New Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)

Private Sub btn_Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Save.Click
Try
If sfd_Save.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim strFileName As String = sfd_Save.FileName
txt_File.Text = strFileName
Dim recfs As New IO.FileStream(strFileName, IO.FileMode.OpenOrCreate)
''接收数据并将其保存到一个新的文件中
Dim recbyte(229888) As Byte
Dim hostsocket As Net.Sockets.Socket = receivesocket.Accept()
''同意和发送端计算机建立连接
Dim newfilestr As New IO.BinaryWriter(recfs) ''流写
hostsocket.Receive(recbyte)
''recfs.Write(recbyte, 0, recbyte.Length - 1)
newfilestr.Write(recbyte, 0, recbyte.Length - 1)
recfs.Close()
hostsocket.Shutdown(Net.Sockets.SocketShutdown.Receive)
hostsocket.Close()
End If
Catch ex As Exception
End Try
End Sub

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim hostipendpiont As New Net.IPEndPoint(Net.IPAddress.Parse("192.168.1.123"), 8888)
receivesocket.Bind(hostipendpiont)
''建立远程计算机的的socket
receivesocket.Listen(2) ''监听socket
Catch ex As Exception
End Try
End Sub
End Class

这例子是我在网上找来后再改了下的,还不能用,你要是做好了,就给我E_Mail一份,谢谢了。 taick@163.com

2007-07-16 17:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-154856-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.434585 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved