FileTransfer

As someone who does a far amount of downloading of stuff – especially technical documents etc I was interested to see that cmdlets had been added to CTP 3 to enable file downloads using BITS.

The recent post from the PowerShell Team http://blogs.msdn.com/powershell/archive/2009/01/11/transferring-large-files-using-bits.aspx

made me want to try it out.  I also spotted the post about copying colourised scripts from PowerShell ISE - http://blogs.msdn.com/powershell/archive/2009/01/13/how-to-copy-colorized-script-from-powershell-ise.aspx – and it has an attachment.  Ok I want that script and I can test out the file transfer stuff.

First up – the file transfer cmdlets can’t be found in PowerShell.  They are in a seperate module that you have to import using

Import-Module FileTransfer –Verbose

You can see the modules available in the PowerShell install directory. There is also one for PSDiagnostics.

Using the –verbose parameter you will see that PowerShell loads an assembly and the format data and then the cmdlets.

The URL of the file we want to download is

$file = "http://blogs.msdn.com/powershell/attachment/9312078.ashx"

Many thanks for making that easy to find.  If you can’t find the URL you want try the technique outlined here - http://blogs.msdn.com/powershell/archive/2009/01/11/finding-a-url-for-file-transfer-cmdlets.aspx

New-FileTransfer -ServerFileName $file -ClientFileNamePrefix c:\scripts -ClientFileName copy-script.zip

–DisplayName  DN1 –Asynchronous

Can be used to perform the download. Make sure you use the client file name prefix (path) and a file name as shown.  The display name identifies the download.  Using –Asynchronous is a good idea if the file is of any size as you cab get on with other things during the download.

To view the download progress we can use

Get-FileTransfer -Name DN1

We are looking for the JobState to change to Transferred. We can then use

$job = Get-FileTransfer -Name DN1
Complete-FileTransfer -BitsJob $job

To complete the process.

The full set of cmdlets for file transfers is

Add-FileTransfer
Clear-FileTransfer
Complete-FileTransfer
Get-FileTransfer
New-FileTransfer
Resume-FileTransfer
Set-FileTransfer
Suspend-FileTransfer

This simple test shows this functionality works and is easy to use.  This is definitely something I will be using more often.  I would recommend that if you are making files available for download you make the URL easy to find – lets get this functionality in use.

 

Technorati Tags: ,,

Leave a Reply