Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 941
Colin Avatar asked Feb 01 '26 03:02

Colin


1 Answers

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
like image 122
hdev Avatar answered Feb 03 '26 01:02

hdev