Reputation: 940
I'm sorry to keep asking about Powershell, my script-foo is not what it needs to be.
I'm writing a BitsTransfer .PS1 to automate the weekly download of an ASCII file.
It never seems to complete and reach a status of "Transferred" and seems stalled in a "Transferring" state. I can see a TMP file in my -Destination folder, with my ASCII data in it.
When I manually download the target file and compare it to the TMP file, they're the same size and appear to have the same first and last records. I assume the download is done.
If I manually run Get-BitsTransfer | Complete-BitsTransfer, the TMP file disappears but still no -Destination file.
My script is nothing sophisticated...
$date= Get-Date -format yyMMdd
$ntispasswd = ConvertTo-SecureString "*******" -AsPlainText -Force
$ntiscreds = New-Object System.Management.Automation.PSCredential ("*******", $ntispasswd)
$jobdescriptor = "DMFWA" + $date
$dmfpath = "C:\DMF"
# -Source https://dmf.ntis.gov/dmldata/weekly/WA$date `
Import-Module BitsTransfer
Start-BitsTransfer `
-DisplayName $jobdescriptor `
-Priority High `
-ProxyUsage Override `
-ProxyList mckwebfilt1:3128 `
-RetryInterval 60 `
-TransferType Download `
-Source https://dmf.ntis.gov/dmldata/weekly/WA130322 `
-Destination $dmfpath\TestWA$date.txt `
-Authentication Basic `
-Credential $ntiscreds `
-Asynchronous
$job = Get-BitsTransfer $displayname
While($Job.Jobstate -ne 'Transferred'){
$job
Start-Sleep -s 1
}
Complete-BitsTransfer $job
Can anybody help me understand what I'm doing wrong?
Upvotes: 3
Views: 9839
Reputation: 11
I used too much time on BitsAdmin trying a transfer a file which was never finished because the file length was not given from the server.
Start-BitsTransfer : Die Dateigröße wurde vom Server nicht zurückgegeben.
Möglicherweise enthält die URL dynamischen Inhalt. Der
Inhaltslängenheader ist in der Server-HTTP-Antwort nicht verfügbar.
In Zeile:1 Zeichen:1
+ Start-BitsTransfer http://***/file c:\users\***\file.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-BitsTransfer],Exception
+ FullyQualifiedErrorId :
StartBitsTransferCOMException,Microsoft.BackgroundIntelligentTransfer.
Management.NewBitsTransferCommand
After trying the same from powershell with Start-BitsTransfer it was the same behavior.
This solution is really awesome and fixed also my problem! Thank you!
$request = New-Object System.Net.Webclient
$passwd = ConvertTo-SecureString "**" -AsPlainText -Force
$request.Credentials = New-Object System.Management.Automation.PSCredential ("**", $passwd)
$request.Downloadstring("https://my full target url")
Upvotes: 1
Reputation: 6507
You did it the right way:
Import-Module BitsTransfer
Start-BitsTransfer -Source $url -Destination $output -Asynchronous
Get-BitsTransfer | Complete-BitsTransfer
Possible failures
$dmfpath\TestWA$date.txt
Get-BitsTransfer | Remove-BitsTransfer
Upvotes: 1
Reputation: 940
This turned out to be a "Royal PITA".
Thank you Kieth, for the hint.
I couldn't get BitTransfer to work properly and resorted to something like this..
$request = New-Object System.Net.Webclient
$passwd = ConvertTo-SecureString "**" -AsPlainText -Force
$request.Credentials = New-Object System.Management.Automation.PSCredential ("**", $passwd)
$request.Downloadstring("https://my full target url")
Upvotes: 0
Reputation: 201592
Look at the last example on this web page about using Start-BitsTransfer and see if that helps.
Upvotes: 0