简体   繁体   中英

Powershell BitsTransfer does not complete

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?

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") 

查看此网页上有关使用Start-BitsTransfer的最后一个示例,看看是否有帮助。

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") 

You did it the right way:

Import-Module BitsTransfer

Start-BitsTransfer -Source $url -Destination $output -Asynchronous    
Get-BitsTransfer | Complete-BitsTransfer

Possible failures

  1. the destination paramater is wrong $dmfpath\\TestWA$date.txt
  2. there are more than 60 BitTransfers running, end them with Get-BitsTransfer | Remove-BitsTransfer Get-BitsTransfer | Remove-BitsTransfer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM