Simple Powershell FTP

With Powershell we can do FTP transaction really easy. The best feature from Powershell is we can use any dll library in our script, we can import .Net libraries and etc into our script. The script below is simple FTP to upload file to FTP server. In this script I’m using System.Net.WebClient to handle the file transfer.

$ftpuser = "user"
$ftppass = "12345"
$ftpserver = "localhost"
$file = "C:\test.txt"
$filenewname = "test.txt"

$webclient = New-Object System.Net.WebClient
$ftp = "ftp://"+$ftpuser+":"+$ftppass+"@"+$ftpserver+"/"+$filenewname
$uri = New-Object System.Uri($ftp)


One thought on “Simple Powershell FTP”

  1. Hey
    $webclient = New-Object System.Net.WebClient

    this code i get following error

    $uri = New-Object System.Uri($ftp)
    New-Object : Exception calling “.ctor” with “1” argument(s): “Invalid URI: A port was expected because of there is a colon (‘:’) present but the port could not be parsed.”

Comments are closed.