Posted By

mafro on 08/26/08


Tagged

download


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

brent-man
mcgraf
D4RKCODE


Download List Of Files


 / Published in: VB.NET
 

Download multiple files listed as filenames in a text file.

  1. Public Class Form1
  2.  
  3. Private Const filenames As String = "c:\list_of_files.txt"
  4. Private Const url As String = "http://remote.host/files/"
  5. Private Const savepath As String = "c:\local\"
  6.  
  7. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8. Dim sr As New IO.StreamReader(filenames)
  9. Dim line As String = sr.ReadLine()
  10.  
  11. Dim req As Net.WebRequest
  12. Dim resp As IO.Stream
  13. Dim out As IO.BinaryWriter
  14.  
  15. Do While line IsNot Nothing
  16. req = Net.HttpWebRequest.Create(url & line)
  17. resp = req.GetResponse().GetResponseStream()
  18.  
  19. out = New IO.BinaryWriter(New IO.FileStream(savepath & line, IO.FileMode.OpenOrCreate))
  20.  
  21. Dim buf(4096) As Byte
  22. Dim k As Int32 = resp.Read(buf, 0, 4096)
  23.  
  24. Do While k > 0
  25. out.Write(buf, 0, k)
  26. k = resp.Read(buf, 0, 4096)
  27. Loop
  28.  
  29. resp.Close()
  30. out.Close()
  31.  
  32. line = sr.ReadLine()
  33. Loop
  34.  
  35. End Sub
  36.  
  37. End Class

Report this snippet  

You need to login to post a comment.