日期:2014-05-19  浏览次数:20841 次

如何实现从服务器上将文件拷贝下来
由于需要做在线更新,请问如何实现从服务器上将文件拷贝下来。要求通过两种方式,第一种直接利用file   uri   来进行copy。另一种利用http   uri来进行copy。主要是做如何通过Http来拷贝。最好利用WCF与服务器通信。
请大侠赐教,不胜感激。

------解决方案--------------------
没用过WCF,我一般用HttpRequest或WebClient。
------解决方案--------------------
你的意思是想,将目标网页内容获取下来吗?如果是可以这样
Try
builder = New StringBuilder
Dim uri As New Uri(Me.txtURL.Text)
builder.Append( "AbsolutePath: " & uri.AbsolutePath & ControlChars.CrLf)
builder.Append( "AbsoluteUri: " & uri.AbsoluteUri & ControlChars.CrLf)
builder.Append( "Host: " & uri.Host & ControlChars.CrLf)
builder.Append( "HostNameType: " & uri.HostNameType.ToString() & ControlChars.CrLf)
builder.Append( "LocalPath: " & uri.LocalPath & ControlChars.CrLf)
builder.Append( "PathAndQuery: " & uri.PathAndQuery & ControlChars.CrLf)
builder.Append( "Port: " & uri.Port & ControlChars.CrLf)
builder.Append( "Query: " & uri.Query & ControlChars.CrLf)
builder.Append( "Scheme: " & uri.Scheme)
Dim request As WebRequest = WebRequest.Create(uri)
Dim response As WebResponse = request.GetResponse()
builder = New StringBuilder
builder.Append( "Request type: " & request.GetType().ToString() & ControlChars.CrLf)
builder.Append( "Response type: " & response.GetType().ToString() & ControlChars.CrLf)
builder.Append( "Content length: " & response.ContentLength & "bytes " & ControlChars.CrLf)
builder.Append( "Content type: " & response.ContentType & ControlChars.CrLf)
builder.Append( "Get HTML code successful! Time: " & DateTime.Now.ToString() & Environment.NewLine & Environment.NewLine)
Dim stream As Stream = response.GetResponseStream()
Dim reader As New StreamReader(stream, System.Text.Encoding.Default)
Dim data As String = reader.ReadToEnd()
reader.Close()
stream.Close()
Me.txtHTML.Text = data
Me.txtResult.Text &= builder.ToString()
getCW = True
Catch ex As Exception
builder = New StringBuilder()
builder.Append( "获取远程Web代码失败: " & ex.Message)
builder.Append( " 时间: " & DateTime.Now.ToString())
builder.Append(Environment.NewLine)
builder.Append(Environment.NewLine)
Me.txtResult.Text &= builder.ToString()
getCW = False
End Try

如果你需要清楚HTML代码 只保留网页内容可以用这个正则表达式来过滤 <\/*[^ <> ]*>
------解决方案--------------------
可以 使用 微软的 智能客户端

http://dev.rdxx.com/NET/WindowsForms/2005-7/27/120622196_3.shtml
------解决方案--------------------
--参考:
http://blog.csdn.net/zlp321002/archive/2006/10/31/1359316.aspx
------解决方案--------------------
写过一个类似的程序,实现局域网更新程序(HTTP一样),如果需要请给我发邮件索取。
seamanhy@sina.com