Using FTP: Downloading Binary File (Part 3)

by Sep 2, 2021

PowerShell does not come with cmdlets to download and upload data via FTP. However, you can use .NET for this.

To download a file from an FTP server in binary mode, try the code below which also illustrates how you can authenticate with explicit credentials:


$localFile = 'C:\test.txt'

$ftprequest.UseBinary = $true
$ftprequest.KeepAlive = $false

    $targetfile = [System.IO.FileStream]::($localFile,[IO.FileMode]::Create)
    [byte[]]$readbuffer = New-Object byte[] 1024

        $readlength = $stream.Read($readbuffer,0,1024)
    while ($readlength -gt 0)

    Write-Warning "Error occurred: $_"

Twitter This Tip! ReTweet this Tip!