473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Example of HTTP file transfer


Can you point me to a simple VB .NET example of how to
receive a file from a web server using a HTTP method
available in .NET

Bob
Nov 21 '05 #1
7 10295
Hi,

Here is a quick example. Add these import statements.

Imports System.Net

Imports System.IO

Sample code

Dim request As WebRequest

Dim response As WebResponse

Dim reader As Stream

Dim writer As Stream

Dim data(1023) As Byte

Dim count As Integer

Dim total As Integer

Me.Show()

Me.Text = "Downloading file ....."

Application.DoEvents()

request =
WebRequest.Create("http://www.onteorasoftware.com/downloads/multigrids.zip")

response = request.GetResponse()

reader = response.GetResponseStream()

ProgressBar1.Maximum = CInt(response.ContentLength)

ProgressBar1.Value = 0

total = 0

writer = File.Create("mylocaldata.zip")

While True

count = reader.Read(data, 0, 1024)

If count <= 0 Then

Exit While

End If

writer.Write(data, 0, count)

total += 1024

If total < ProgressBar1.Maximum Then ProgressBar1.Value = total

Application.DoEvents()

End While

reader.Close()

writer.Close()

Ken

--------------------------
"BobAchgill" <an*******@discussions.microsoft.com> wrote in message
news:10****************************@phx.gbl...

Can you point me to a simple VB .NET example of how to
receive a file from a web server using a HTTP method
available in .NET

Bob
Nov 21 '05 #2
Beautiful! Thanks Ken.

Is it possible to get a files detail list, too, with HTTP?

But, hey, I am so thankful to get what you gave... it helps me out a
whole lot!

Bob

Nov 21 '05 #3
Bob,

I was assuming this was a double post with the webservice and it (is) was
not clear for me which you asked.

This one is a very short one for what you ask about a http webserver.
\\\\
webclient.downloadfile(url,filePath)
////
I hope this helps?

Cor
Nov 21 '05 #4
So as I understand the only difference between the two methods for
downloading a file from an HTTP web site is:
- webclient.downloadfile(url,filePath) is short and sweet and to
the point for getting the file down
- WebRequest.Create("url") lets you also do things like monitor
progress or choose to work Asyn

Do either have the ability to see the file datestamp on the server? I
guess that is asking to much of HTTP. Only FTP does datestamps.

Bob

Nov 21 '05 #5
Bob,

To get information. It is changed in this message so when you have errors
try to correct it or reply.
There are a lot of webheaders as you see as "content-length"

\\\
dim conlength as string
Dim wbRq As DirectCast(WebRequest.Create(item.Text), HttpWebRequest)
wbRq.Timeout = 2000
Try
Dim wbRs As DirectCast(wbRq.GetResponse(), HttpWebResponse)
Dim wbHCol As WebHeaderCollection = wbRs.Headers
For i As Integer = 0 To wbHCol.Count - 1
Dim header As String = wbHCol.GetKey(i)
Dim values As String() = wbHCol.GetValues(header)
If values.Length > 0 andalso header.Tolower = "content-length" Then
conlenght = values(0)
End If
Next
wbRs.Close()
Catch
conlength = "?"
End Try
///
I hope this helps?

Cor
Nov 21 '05 #6
"Cor Ligthert" <no************@planet.nl> schrieb:
Dim wbRq As DirectCast(WebRequest.Create(item.Text), HttpWebRequest)


LOL!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7
Bob,

Herfried saw that I used VB 2007

:-)

Here is a sample that is tested

You can see in it today that it is the last updated at
Last-Modified Tue, 01 Feb 2005 11:08:47 GMT

\\\
Public Class Herfrieds
Public Shared Sub Main()
Dim conlength As String
Dim wbRq As Net.HttpWebRequest = _
DirectCast(Net.WebRequest.Create _
("http://dotnet.mvps.org/"), Net.HttpWebRequest)
wbRq.Timeout = 2000
Try
Dim wbRs As Net.HttpWebResponse = DirectCast(wbRq.GetResponse(),
_
Net.HttpWebResponse)
Dim wbHCol As Net.WebHeaderCollection = wbRs.Headers
For i As Integer = 0 To wbHCol.Count - 1
Dim header As String = wbHCol.GetKey(i)
Dim values As String() = wbHCol.GetValues(header)
If values.Length > 0 Then
Console.Write(header)
Console.Write(" ")
Console.Write(values(0))
Console.Write(vbCrLf)
End If
Next
wbRs.Close()
Catch
Console.Write("could not get something")
End Try
End Sub
End Class
///
I hope this helps a little bit better?

:-)

Cor
Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Neel Word | last post by:
I need to develop an application (development platform: Win2000; target platform: Win98/ME/NT4/2000/XP), which would require file transfer functionality over dial-up and network. We could...
1
by: uballing | last post by:
I am writing a "Windows Update" type application where via Web Services the client checks with the Server if he needs to download a newer version of a set of DLLs and EXE If there is a newer...
2
by: Landley | last post by:
Dear Fellow Coders, I am attempting to send files using UDP. I had no problem sending small files, but when the files were over a certain size an exception was thrown. It was moaning about the...
2
by: Chris | last post by:
Hi. I am trying to write a vb.net program to send large files via TCP. I was wondering if there was a code example or book that demonstrates how to write a simple file transfer program of large...
10
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an...
7
by: shadowman | last post by:
Hello all: I have a web app that creates an image of a graph (as a png), based on user input of a combination of drop-down box items. I'm trying to add a function that allows the user to save...
0
by: fiona | last post by:
Yucca Valley, CA, - October 2007: Catalyst Development Corporation, publisher of SocketTools, SocketWrench and LogicGem, today announced the release of Catalyst File Transfer .NET V5.0. For...
1
by: snranand | last post by:
Can some one point me to a simple java example of how to transfer files using HTTP
5
by: Johnny Jörgensen | last post by:
Has anybody got a link to an example of how you transfer files between two computers over the internet (P2P style)? I have no idea where to start and all example I can find seems to be done in...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.