How to view the files on an FTP server using Windows PowerShell

Home > Search > How-to

To view the files on an FTP server:

#Unique Variables
$FTPServer = ""
$FTPUsername = "username"
$FTPPassword = "password" 

#Connection String
$credentials = new-object System.Net.NetworkCredential($FTPUsername, $FTPPassword)

#Function to view the files in the FTP Server
function View-Files-in-FTP-Server ($url,$credentials) {
    $request = [Net.WebRequest]::Create($url)
    $request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
    if ($credentials) { $request.Credentials = $credentials }
    $response = $request.GetResponse()
    $reader = New-Object IO.StreamReader $response.GetResponseStream() 

#Use the root directory of the FTP Server
$folderPath= $FTPServer + "/" + $folder + "/"
$ListFiles=View-Files-in-FTP-Server -url $folderPath -credentials $credentials
$files = ($ListFiles -split "`r`n")


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter in the box below so that we can be sure you are a human.