1

I'm trying to set up a service where I can transfer a number of files to our IIS server using Microsoft BITS.

I've installed the required components on the IIS server and have successfully uploaded several files but it is unreliable as soon as I add authentication to the virtual directory.

I'm using this code fragment to do the transfer:

Get-ChildItem $sourcePath | % {
    try
    {
        Start-BitsTransfer -Source $_.FullName -Destination "$destinationPath/$_" -TransferType Upload -Authentication Basic -Credential $credentials
    }
    catch
    {
        $_
    }
}

If I leave out the authentication and credentials parameters and enable anonymous authentication, it works every time.

If I turn off anonymous authentication, add basic authentication and set $credentials to be my domain and username, it asks for the password and works every time. Same with digest authentication.

If I use basic authentication and set up credentials with the following code, it works the first time and fails after that. If I wait a bit and try again, it sometimes resets and works first time then fails after that. Same with digest authentication.

The code that I use to set up the credentials is as follows:

$username = "mydomain\myuser"
$password = "mypassword"

$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $securePassword)

The error that it gives when it fails is:

Start-BitsTransfer : Value does not fall within the expected range.
At D:\Projects\Powershell\MoveFiles.ps1:48 char:9
+         Start-BitsTransfer -Source $_.FullName -Destination "$destinationPath/$_ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Start-BitsTransfer], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.BackgroundIntelligentTransfer.Management.NewBitsTransferCommand

The results are the same whether I use HTTP or HTTPS and the failed attempts aren't present in the IIS logs.

Has anyone got any ideas what the problem is? I think that it is a Powershell problem because it does work if I type in the password rather than set it up in Powershell.

A final bit of information that I've discovered... I wrote a simple BITS upload program using Sharp BITS and it worked with no issues.

Steve Kaye
  • 6,262
  • 2
  • 23
  • 27
  • -Destination "$destinationPath/$_" Could be causing intermittent issues depending on the value of $_. That error indicates a problem with one of the parameters, specifically it is out of range (too big, or long?) Also what happens when the destination is in use? – Jan Chrbolka May 04 '15 at 04:21
  • At this point, there isn't any possibility of the files being in use because the next part of the process hasn't been implemented yet. If it were a problem with the $_ parameter, you'd expect the same intermittent issues with anonymous authentication and I'm not seeing that. – Steve Kaye May 05 '15 at 06:51
  • Still don't like it. $_ is a file system object and you are sending it as output paramater. Can you at least use sometholing like $_.Name? Please? – Jan Chrbolka May 05 '15 at 06:58
  • I came to try this change to find that I'm already using `$_.Name` instead of `$_`. I've tried quite a few things since my post and this must have been one of them. – Steve Kaye May 05 '15 at 09:11
  • Another stupid question then... Do you always encrypt credentials on the fly and on the same originating computer that they are used from? – Jan Chrbolka May 05 '15 at 22:57
  • Is that what `ConvertTo-SecureString` does? If so, yes. It's done on the fly on the computer that I'm uploading the data from. – Steve Kaye May 06 '15 at 13:11

0 Answers0