求vb2005读取/下载/上传ftp代码

想飞的狼 2009-04-06 06:10:09
求vb2005读取/下载/上传ftp代码


请高手帮忙,越详细越好
...全文
246 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
zoucaiwang0402 2009-10-27
  • 打赏
  • 举报
回复
Try
Dim MyRequest As System.Net.FtpWebRequest = CType(System.Net.WebRequest. _
Create("ftp://www.163.com/1.swf"), _
System.Net.FtpWebRequest)
MyRequest.Credentials = New System.Net.NetworkCredential( _
"username", "password")
Dim MyResponse As System.Net.FtpWebResponse = _
CType(MyRequest.GetResponse(), System.Net.FtpWebResponse)
Dim MyData As System.IO.Stream = MyResponse.GetResponseStream()
Dim MySavePath As String = "1.swf"
If (System.IO.File.Exists(MySavePath)) Then
System.IO.File.Delete(MySavePath)
End If
Dim MyBuffer(4096) As Byte
Dim MyStream As New System.IO.FileStream( _
MySavePath, System.IO.FileMode.CreateNew)
Dim Count As Integer = 0
Count = MyData.Read(MyBuffer, 0, MyBuffer.Length)
While (Count > 0)
MyStream.Write(MyBuffer, 0, Count)
Count = MyData.Read(MyBuffer, 0, MyBuffer.Length)
End While
MessageBox.Show("文件下载操作完成!", "信息提示", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message, "信息提示", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
想飞的狼 2009-04-11
  • 打赏
  • 举报
回复
thanks
Roc_Lee 2009-04-10
  • 打赏
  • 举报
回复
WebClient
使用这个类,自己有相关方法
chyyyin 2009-04-10
  • 打赏
  • 举报
回复
的确,试过了,WebClient这个类真是好啊!直接有上传,下载的方法!
sunshine_anycall 2009-04-08
  • 打赏
  • 举报
回复
mark
yifan__ 2009-04-08
  • 打赏
  • 举报
回复
收藏~~
yifan__ 2009-04-08
  • 打赏
  • 举报
回复
收藏~~
qshurufa 2009-04-07
  • 打赏
  • 举报
回复
路过
chyyyin 2009-04-07
  • 打赏
  • 举报
回复
学习~
outou 2009-04-07
  • 打赏
  • 举报
回复
参考下面的代码。来自http://bingning.net/VB/SOURCE/internet/ftpwebclient.html
下载代码

'WebClient对象作成
Dim wc As New System.Net.WebClient()
'指定用户名和密码
wc.Credentials = New System.Net.NetworkCredential("username", "password")
'从FTP服务器下载
wc.DownloadFile("ftp://localhost/test.txt", "C:\test.txt")
'释放资源
wc.Dispose()


上传代码

'WebClient对象作成
Dim wc As New System.Net.WebClient()
'指定用户名和密码
wc.Credentials = New System.Net.NetworkCredential("username", "password")
'向FTP服务器上传文件
wc.UploadFile("ftp://localhost/test.txt", "C:\test.txt")
'释放资源
wc.Dispose()
bw555 2009-04-06
  • 打赏
  • 举报
回复
'下载
Dim dfile As New WebClient
dfile.DownloadFile(Me.M_Url, Me.M_FileName)
'上传
Dim dfile As New WebClient
dfile.UploadFile(Me.M_Url, Me.M_FileName)
'获得ftp文件大小
Dim reqFtp As FtpWebRequest
reqFtp = CType(FtpWebRequest.Create(New Uri(url)), FtpWebRequest)
reqFtp.Proxy = Nothing
reqFtp.Method = WebRequestMethods.Ftp.GetFileSize
Dim response As WebResponse
response = reqFtp.GetResponse()
Return response.ContentLength()
wuyq11 2009-04-06
  • 打赏
  • 举报
回复
chyyyin 2009-04-06
  • 打赏
  • 举报
回复
其实就是一个Socket通信的问题,用UDP协议应该可以满足数据传输需求!
支持~楼主加油!

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧