Search code examples
vb.netvisual-studio-2013file-transferweb-to-winforms

create txtfile from website and save to server


I have attempted to find a way to download a file (from a PC running a Winform written in VB) from a web directory but could not get this done due to the date stamp that gets generated once the file is saved (filename must be precise). So now I'm trying the reverse (saving the file to the PC directly from the creation of the file).

Does anyone have any suggestions on methods to use (please no FTP due to proxy restrictions, same goes for client/server TCP/UDP). this will always be a .txt file.

thanks in advance.


Solution

  • If you can see the file contents by navigating to the URL, you can use an HttpWebRequest and a StreamReader / StreamWriter to save the data.

    I'm downloading an example from http://textfiles.com/100/914bbs.txt

        Dim request As HttpWebRequest
    
        request = WebRequest.Create("http://textfiles.com/100/914bbs.txt")
    
        request.Method = "GET"
    
        Dim response = request.GetResponse
    
        Using reader As New StreamReader(response.GetResponseStream)
    
            Using writer As New StreamWriter("C:\myfilename.txt")
                writer.Write(reader.ReadToEnd)
            End Using
    
        End Using