Hi Thomas!! use this!
[code]
Private Sub DownloadVM(ByVal VMName As String)
Dim MyVirtualMachine As VMware.Vim.VirtualMachine = GetVM(VMName)
Dim ExportedMoR As VMware.Vim.ManagedObjectReference = MyVirtualMachine.ExportVm
Dim MyLease As New VMware.Vim.HttpNfcLease(Client, ExportedMoR)
Dim MyLeaseinfo As VMware.Vim.HttpNfcLeaseInfo
Dim MyleaseState As VMware.Vim.HttpNfcLeaseState
Dim MyProgress As Integer
Dim Myerror As New LocalizedMethodFault
RetrieveHttpNfcLeaseProperties(Client, ExportedMoR, MyLeaseinfo, MyleaseState, MyProgress, Myerror)
MyLeaseinfo.LeaseTimeout = (300 * 1000 * 1000)
'Dim MyLeaseinfo As VMware.Vim.HttpNfcLeaseInfo = MyVal.Info
'MyLeaseinfo.LeaseTimeout = (300 * 1000 * 1000)
Do While MyleaseState <> VMware.Vim.HttpNfcLeaseState.ready
Debug.WriteLine("Not Ready: " & MyleaseState)
Threading.Thread.Sleep(500)
RetrieveHttpNfcLeaseProperties(Client, ExportedMoR, MyLeaseinfo, MyleaseState, MyProgress, Myerror)
Loop
Debug.WriteLine("Ready")
For Each MyUrl As VMware.Vim.HttpNfcLeaseDeviceUrl In MyLeaseinfo.DeviceUrl
Debug.WriteLine(MyUrl.Url)
Debug.WriteLine(MyUrl.FileSize)
Debug.WriteLine(MyUrl.Key)
Debug.WriteLine(MyUrl.DatastoreKey)
Debug.WriteLine(MyUrl.SslThumbprint)
Dim fileName As String = "c:\ExportedVM.vmdk"
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Concatenate the domain with the Web resource filename. Because DownloadFile
'requires a fully qualified resource name, concatenate the domain with the Web resource file name.
Debug.WriteLine("Downloading File """ & fileName & """ from """ & MyUrl.Url & """ ......." + ControlChars.Cr + ControlChars.Cr)
' The DownloadFile() method downloads the Web resource and saves it into the current file-system folder.
myWebClient.DownloadFile(MyUrl.Url, fileName)
Debug.WriteLine("Successfully Downloaded file """ & fileName & """ from """ & MyUrl.Url & """")
Debug.WriteLine((ControlChars.Cr + "Downloaded file saved in the following file system folder:" + ControlChars.Cr + ControlChars.Tab + Application.StartupPath))
Next
MyLease.HttpNfcLeaseComplete()
End Sub
Private Sub RetrieveHttpNfcLeaseProperties(VimClient As VimClient, httpNfcLeaseMor As ManagedObjectReference, ByRef httpNfcLeaseInfo As HttpNfcLeaseInfo, ByRef httpNfcLeaseState__1 As HttpNfcLeaseState, ByRef httpNfcLeaseInitializeProgress As Integer, ByRef httpNfcLeaseError As LocalizedMethodFault)
httpNfcLeaseInfo = Nothing
httpNfcLeaseState__1 = HttpNfcLeaseState.[error]
httpNfcLeaseInitializeProgress = 0
httpNfcLeaseError = Nothing
Dim propertyCollector As New PropertyCollector(VimClient, VimClient.ServiceContent.PropertyCollector)
Dim objectContent As ObjectContent() = propertyCollector.RetrieveProperties({ViewBase.GetPropertyFilterSpec(httpNfcLeaseMor)})
If (objectContent IsNot Nothing) AndAlso (objectContent.Length > 0) Then
For Each [property] As DynamicProperty In objectContent(0).PropSet
Debug.WriteLine([property].Name)
Select Case [property].Name
Case "info"
httpNfcLeaseInfo = DirectCast([property].Val, HttpNfcLeaseInfo)
Exit Select
Case "state"
Dim state As String
If TypeOf [property].Val Is XmlNode() Then
state = DirectCast([property].Val, XmlNode())(1).Value
Else
state = [property].Val.ToString()
End If
httpNfcLeaseState__1 = DirectCast([Enum].Parse(GetType(HttpNfcLeaseState), state), HttpNfcLeaseState)
Exit Select
Case "initializeProgress"
httpNfcLeaseInitializeProgress = CInt([property].Val)
Exit Select
Case "error"
httpNfcLeaseError = DirectCast([property].Val, LocalizedMethodFault)
Exit Select
End Select
Next
End If
End Sub
[/code]