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
Joined January 20, 2005
__J___262279
Jan 10, 2017Nimbostratus
In 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 { }
}