Automate FTP Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

FTP ADO.NET Provider

An easy-to-use database-like interface for .NET applications access to remote files and directories.

Are you looking for a quick and easy way to access FTP data from PowerShell? We show how to use the Cmdlets for FTP and the CData ADO.NET Provider for FTP to connect to FTP data and synchronize, automate, download, and more.

The CData Cmdlets for FTP are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to FTP.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the FTP API, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete FTP data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for FTP. To access FTP data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for FTP.

After obtaining the needed connection properties, accessing FTP data in PowerShell consists of three basic steps.

To connect to FTP or SFTP servers, specify at least RemoteHost and FileProtocol. Specify the port with RemotePort.

Set User and Password to perform Basic authentication. Set SSHAuthMode to use SSH authentication. See the Getting Started section of the data provider help documentation for more information on authenticating via SSH.

Set SSLMode and SSLServerCert to secure connections with SSL.

The data provider lists the tables based on the available folders in your FTP server. Set the following connection properties to control the relational view of the file system:

  • RemotePath: Set this to the current working directory.
  • TableDepth: Set this to control the depth of folders to list as views.
  • FileRetrievalDepth: Set this to retrieve and list files recursively from the root table.

Stored Procedures are available to download files, upload files, and send protocol commands. See the Data Model chapter of the FTP data provider documentation for more information.


  1. Install the module:

    Install-Module FTPCmdlets
  2. Connect:

    $ftp = Connect-FTP -RemoteHost "$RemoteHost"
  3. Search for and retrieve data:

    $filepath = "/documents/doc.txt" $mydirectory = Select-FTP -Connection $ftp -Table "MyDirectory" -Where "FilePath = `'$FilePath`'" $mydirectory

    You can also use the Invoke-FTP cmdlet to execute SQL commands:

    $mydirectory = Invoke-FTP -Connection $ftp -Query 'SELECT * FROM MyDirectory WHERE FilePath = @FilePath' -Params @{'@FilePath'='/documents/doc.txt'}


  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for FTP\lib\System.Data.CData.FTP.dll")
  2. Connect to FTP:

    $conn= New-Object System.Data.CData.FTP.FTPConnection("RemoteHost=MyFTPServer;") $conn.Open()
  3. Instantiate the FTPDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Filesize, Filename from MyDirectory" $da= New-Object System.Data.CData.FTP.FTPDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.filesize $_.filename }

Update FTP Data


Update-FTP -Connection $FTP -Columns @('Filesize','Filename') -Values @('MyFilesize', 'MyFilename') -Table MyDirectory -Id "MyId"


$cmd = New-Object System.Data.CData.FTP.FTPCommand("UPDATE MyDirectory SET FilePath='/documents/doc.txt' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.FTP.FTPParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert FTP Data


Add-FTP -Connection $FTP -Table MyDirectory -Columns @("Filesize", "Filename") -Values @("MyFilesize", "MyFilename")


$cmd = New-Object System.Data.CData.FTP.FTPCommand("INSERT INTO MyDirectory (FilePath) VALUES (@myFilePath)", $conn) $cmd.Parameters.Add(new System.Data.CData.FTP.FTPParameter("@myFilePath","/documents/doc.txt")) $cmd.ExecuteNonQuery()

Delete FTP Data


Remove-FTP -Connection $FTP -Table "MyDirectory" -Id "MyId"


$cmd = New-Object System.Data.CData.FTP.FTPCommand("DELETE FROM MyDirectory WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.FTP.FTPParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()