Demystifying iControl REST Part 5: Transferring Files
iControl REST. It’s iControl SOAP’s baby, brother, introduced back in TMOS version 11.4 as an early access feature but released fully in version 11.5.
Several articles on basic usage have been wri...
Updated Aug 04, 2023
Version 5.0JRahm
Admin
Christ Follower, Husband, Father, Technologist. I love community and I especially love THIS community. My background is networking, but I've dabbled in all the F5 iStuff, I'm a recovering Perl guy, and am very much a python enthusiast. Learning alongside all of you in this accelerating industry toward modern apps and architectures.__J___262279
Nimbostratus
Jan 10, 2017In case anyone else struggled with this in powershell (I sure did for a bit). Here is an simple function that will do the trick.
function F5-RestFileUpload
{
<
.SYNOPSIS
Upload a file to the BigIP
.DESCRIPTION
Uploads file to the F5 in to /var/config/rest/downloads directory.
.EXAMPLE
F5-RestFileUpload -InFile "C:\certs\mycert.pxf" -BigIP "mybigip.local" -Credential $mycreds
>
[CmdletBinding()]
PARAM
(
[string][parameter(Mandatory = $true)][ValidateNotNullOrEmpty()]$InFile,
[string][parameter(Mandatory = $true)][ValidateNotNullOrEmpty()]$BigIP,
[System.Management.Automation.PSCredential]$Credential
)
BEGIN
{
$file = Get-ChildItem $InFile
$byte = Get-Content $file.FullName -Encoding Byte
$ContentType = "application/octet-stream"
$ContentRange = "0-{0}/{1}" -f ($file.length -1), $file.length
$path = "/mgmt/shared/file-transfer/uploads"
$uri = "https://{0}{1}/{2}" -f $BigIP, $path, $file.name
$uri = New-Object System.Uri $uri
}
PROCESS
{
$webclient = New-Object System.Net.WebClient
$webclient.Headers.Add("ServerHost", $uri.DnsSafeName);
$webclient.Headers.Add("Content-Type", $ContentType)
$webclient.Headers.Add("Content-Range", $ContentRange)
$webclient.Credentials = $Credential
try
{
$response = $webclient.uploaddata($uri.AbsoluteUri, $byte)
}
catch [Exception]
{
$PSCmdlet.ThrowTerminatingError($_)
}
finally
{
if($null -ne $webclient)
{
$webclient.Dispose()
}
}
}
END { }
}