' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.IO
Imports System.Net

Public Class FileUpload
    Private Const BOUNDARY As String = "ArneArne"
    Public Shared Sub Main(args As String())
        upload("http://localhost/upload.php", "C:\z.txt")
    End Sub
    Public Shared Sub upload(url As String, textfile As String)
        Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
        req.Method = "POST"
        req.ContentType = "multipart/form-data, boundary=" & BOUNDARY
        Dim post As New StreamWriter(req.GetRequestStream())
        post.WriteLine("--" & BOUNDARY)
        post.WriteLine("Content-disposition: form-data; name=""f""; filename=""" & Path.GetFileName(textfile) & """")
        post.WriteLine("Content-type: text/plain")
        post.WriteLine("")
        Dim txtf As New StreamReader(New FileStream(textfile, FileMode.Open))
        Dim line As String
        line = txtf.ReadLine()
        While line IsNot Nothing
            post.WriteLine(line)
            line = txtf.ReadLine()
        End While
        txtf.Close()
        post.WriteLine("--" & BOUNDARY & "--")
        post.Close()
        Dim resp As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
        Console.WriteLine(resp.StatusCode)
        resp.Close()
    End Sub
End Class
