Hi Russell,
I think the WebClient doesnot support the timeout properties, you may try
to use the HttpWebRequest to achieve your aim. Here goes the sample code.
I converted from C# code in the link below
http://www.netacademia.net/tudastar/default.asp?upid=554
Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Namespace HttpCopy
Class App
Private args() As String
Private cred As ICredentials
Public Shared Sub Main(ByVal args() As String)
Dim app As New App
app.args = args
app.Run()
End Sub 'Main
Private Sub Run()
If args.Length < 2 Then
Usage()
Return
End If
Dim [source] As String = args(0)
Dim dest As String = args(1)
If CheckArgs() Then
cred = MakeCredentials()
If Directory.Exists([source]) Then
'Source is a folder, we have to enumerate
'all the files (not recursive)
If Not dest.EndsWith("/") Then
Console.WriteLine(("If source is a folder
destination must be" + " a folder too (/ at the end of it)."))
Return
End If
Dim file As String
For Each file In Directory.GetFiles([source])
CopyFileWithProgress(file, dest +
Path.GetFileName(file))
Next file
Else
'Only a file
If dest.EndsWith("/") Then
dest += Path.GetFileName([source])
End If
CopyFileWithProgress([source], dest)
End If
End If
End Sub 'Run
Private Sub CopyFileWithProgress(ByVal [source] As String, ByVal
dest As String)
Dim wt As TimeSpan
If CopyFile([source], dest, wt) Then
Console.WriteLine("Successfully copied in {0}.{1} sec.",
wt.Seconds, wt.Milliseconds)
End If
End Sub 'CopyFileWithProgress
Private Function CopyFile(ByVal [source] As String, ByVal dest As
String, ByRef workingTime As TimeSpan) As Boolean
Dim startTime As System.DateTime = DateTime.Now
Dim completed As Boolean = False
Dim response As String = Nothing
Try
Dim uploader As HttpWebRequest =
CType(WebRequest.Create(New Uri(dest)), HttpWebRequest)
uploader.Timeout = 60000000
uploader.Method = "PUT"
uploader.ContentLength = New FileInfo([source]).Length
uploader.Credentials = cred
Dim sourceStream As New FileStream([source], FileMode.Open,
FileAccess.Read, FileShare.ReadWrite)
Console.WriteLine("Copying {0} to {1}",
Path.GetFullPath([source]), dest)
Dim requestStream As Stream = uploader.GetRequestStream()
Dim buff(4095) As Byte
Dim pos As Integer = 0
pos = sourceStream.Read(buff, 0, buff.Length)
While pos <> 0 'ToDo: Unsupported feature: assignment
within expression.
requestStream.Write(buff, 0, pos)
pos = sourceStream.Read(buff, 0, buff.Length)
End While
Dim resp As HttpWebResponse = CType(uploader.GetResponse(),
HttpWebResponse)
Dim respReader As New StreamReader(resp.GetResponseStream())
response = respReader.ReadToEnd()
completed = True
Catch ex As Exception
Console.WriteLine("Error while uploading file {0}, a hiba
oka:" + ControlChars.Lf + " {1}", [source], ex)
Console.WriteLine(ControlChars.Lf + "Http response:" +
ControlChars.Lf + " {0}", IIf(response Is Nothing, "No Response", response))
Finally
workingTime = System.DateTime.op_Subtraction(DateTime.Now,
startTime)
End Try
Return completed
End Function 'CopyFile
Private Function MakeCredentials() As ICredentials
Dim user, pass, domain As String
user = GetSwitchValue("user")
pass = GetSwitchValue("password")
domain = GetSwitchValue("domain")
If domain Is Nothing Then
domain = ""
End If
If Not (user Is Nothing) Then
Return New NetworkCredential(user, pass, domain)
Else
Return CredentialCache.DefaultCredentials
End If
End Function 'MakeCredentials
Private Function GetSwitchValue(ByVal switchName As String) As
String
switchName = switchName.ToLower()
Dim arg As String
For Each arg In args
If arg.ToLower().StartsWith(("/" + switchName + ":")) Then
Return arg.Split(":".ToCharArray())(1).Trim()
End If
Next arg
Return Nothing
End Function 'GetSwitchValue
Private Function CheckArgs() As Boolean
'is dest a valid uri?
Try
Dim destUri As New Uri(args(1))
Return True
Catch
Console.WriteLine("Invalid destination URL: {0}", args(1))
Return False
End Try
End Function 'CheckArgs
Private Sub Usage()
Dim usage As String = "httpcopy: copies local files to http
server via HTTP PUT method." + ControlChars.Cr + ControlChars.Lf +
"Copyright (C) NetAcademia 1900-2003. No right reserved." + ControlChars.Cr
+ ControlChars.Lf + "Author: (e-mail address removed)" + ControlChars.Cr
+ ControlChars.Lf + "Usage:" + ControlChars.Cr + ControlChars.Lf +
"httpcopy sourceFile destFile" + " [/user:uname, /password
ass,
/domain:dname]" + ControlChars.Cr + ControlChars.Lf + "Examples:" +
ControlChars.Cr + ControlChars.Lf + "httpcopy a.txt
http://www.netacademia.net/xxx/b.txt" + ControlChars.Cr + ControlChars.Lf +
"httpcopy a.txt
http://www.netacademia.net/xxx/" + ControlChars.Cr +
ControlChars.Lf + "httpcopy c:\temp
http://www.netacademia.net/xxx/" +
ControlChars.Cr + ControlChars.Lf
Console.WriteLine(usage)
End Sub 'Usage
End Class 'App
End Namespace 'HttpCopy
If you have any concern on this issue, please post here.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure!
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.