Published in: VB.NET
Download multiple files listed as filenames in a text file.
Public Class Form1 Private Const filenames As String = "c:\list_of_files.txt" Private Const url As String = "http://remote.host/files/" Private Const savepath As String = "c:\local\" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sr As New IO.StreamReader(filenames) Dim line As String = sr.ReadLine() Dim req As Net.WebRequest Dim resp As IO.Stream Dim out As IO.BinaryWriter Do While line IsNot Nothing req = Net.HttpWebRequest.Create(url & line) resp = req.GetResponse().GetResponseStream() out = New IO.BinaryWriter(New IO.FileStream(savepath & line, IO.FileMode.OpenOrCreate)) Dim buf(4096) As Byte Dim k As Int32 = resp.Read(buf, 0, 4096) Do While k > 0 out.Write(buf, 0, k) k = resp.Read(buf, 0, 4096) Loop resp.Close() out.Close() line = sr.ReadLine() Loop End Sub End Class
You need to login to post a comment.
