-3

I am using vb.net ( i'm amateur ) and i am trying to make my program to download a file from my ftp server . It should read a text file from a link , line by line and on each line is a word .

Text file is something like :

  • first
  • second
  • third

It must add each line content to a link and then download it . After it downloads the first line it must go to the second and so on . I don't know if its possible and i really hope someone can help me . Thank you .

LG .Radu
  • 13
  • 4
  • Search online how to download and read files using FTP. Then post your code and explain what your problem is, don't just ask for code without you even trying – Keith Mifsud Jun 05 '15 at 09:40
  • Welcome to Stack Overflow! please have a look at the [Help](http://stackoverflow.com/help) center, in the **Asking** section to learn how to ask proper questions. on topic: yes this is very possible, you need to do a research first and attempt to solve the problem yourself, and if you get stuck in the middle then feel free to post back and we will try to help you. – Banana Jun 05 '15 at 09:41
  • i am trying . thats only a part from my program . i know how to download and read files but i dont know how to transform the line of a text file into a string and then repeat the loop until the end of the text . – LG .Radu Jun 05 '15 at 09:41
  • also: http://stackoverflow.com/questions/23478533/read-text-file-from-ftp and http://stackoverflow.com/questions/6098694/read-file-from-ftp – Keith Mifsud Jun 05 '15 at 09:43
  • @LG.Radu your laziness is overwhelming me, just google how to read all lines from a file for god's sake, [Here](https://msdn.microsoft.com/en-us/library/s2tte0y1(v=vs.110).aspx) is the first result that comes up – Banana Jun 05 '15 at 09:45

1 Answers1

0

This code does what you need:

Dim FileLink As String = "yourserver/file.txt" 'Link to your text file
Dim Destination As String = "C:\" 'Link to the download directory
Dim Client As WebClient = New WebClient() 'New web client
Dim Reader As StreamReader = New StreamReader(Client.OpenRead(FileLink)) 'A stream reader to get your file contents
Dim A As String = Reader.ReadToEnd 'Outputing the file contents to A
Dim Phase As Integer = 0 'A phase which determens which line you're at
Dim Links(500) As String 'A string array to hold 500 links, you can edit the number
For I As Integer = 0 To A.Length 'Looping through A
If A(I) = Environment.NewLine Then 'If the current character is a newline, it'll start downloading the from the first link and increase the Phase 
My.Computer.Network.DownloadFile(Links(Phase), Destination, "", "", False, 9800, True) 'Link, destination, id, password, show UI or not, timeout, overwrite or not
Phase += 1
Else 'If it's not a newline then the link is still incomplete, it adds the character to the link currently being written
Links(Phase) += A(I)
End If
Next
Remon Ramy
  • 167
  • 1
  • 11
  • hei . thank you very very much :D but i have a strange problem . it doesnt update the text file . i mean i edited it in ftp , it downloaded again but it is still with the old info . i removed temp still the same . thank you – LG .Radu Jun 05 '15 at 14:55