' Command line arguments are two strings:
' 1. The url that is the name of the file being uploaded to the server.
' 2. The name of the file on the local machine.
'
Public Shared Sub Main(ByVal args() As String)
' Create a Uri instance with the specified URI string.
' If the URI is not correctly formed, the Uri constructor
' will throw an exception.
Dim waitObject As ManualResetEvent
Dim target As New Uri(args(0))
Dim fileName As String = args(1)
Dim state As New FtpState()
Dim request As FtpWebRequest = CType(WebRequest.Create(target), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.UploadFile
' This example uses anonymous logon.
' The request is anonymous by default; the credential does not have to be specified.
' The example specifies the credential only to
' control how actions are logged on the server.
request.Credentials = New NetworkCredential("anonymous", "janeDoe@contoso.com")
' Store the request in the object that we pass into the
' asynchronous operations.
state.Request = request
state.FileName = fileName
' Get the event to wait on.
waitObject = state.OperationComplete
' Asynchronously get the stream for the file contents.
request.BeginGetRequestStream(New AsyncCallback(AddressOf EndGetStreamCallback), state)
' Block the current thread until all operations are complete.
waitObject.WaitOne()
' The operations either completed or threw an exception.
If state.OperationException IsNot Nothing Then
Throw state.OperationException
Else
Console.WriteLine("The operation completed - {0}", state.StatusDescription)
End If
End Sub