Using FTP: Uploading File (Part 4)

by Sep 6, 2021

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

To upload a file from your local drive to an FTP server, try the code below:

$localFile = "C:\test.txt"

$username='testuser'
$password='P@ssw0rd'

[System.Uri]$uri = "ftp://${username}:$password@192.168.1.123/test.txt"
$webclient = [System.Net.WebClient]::new()
$webclient.UploadFile($uri, $localFile)
$webclient.Dispose()


Twitter This Tip! ReTweet this Tip!