Powershell FTP

I've been looking for a replacement for my powershell script used to ftp files.  It currently uses the Windows ftp.exe application with a command file.  Well the script has been causing problems and files have been truncated or lost.  I decided to look into a replacement.

I tried ftpwebrequest but when moving multiple files the login happens over and over.

I found Alex FTPS Client on codeplex at http://ftps.codeplex.com/  Seems to do what I needed. 

Here is a Powershell script to use it to connect, list contents, get the files and put the files

add-type -path "C:\AlexPilotti.FTPS.Client.dll"

$ftpServer = "ftp.someftp.com"
$username ="validUser"
$password ="myPassword"
$localToFTPPath = "C:\ToFTP"
$localFromFTPPath = "C:\FromFTP"
$remotePickupDir = "/Inbox"
$remoteDropDir = "/Outbox"
$SSLMode = [AlexPilotti.FTPS.Client.ESSLSupportMode]::ClearText

$ftp = new-object "AlexPilotti.FTPS.Client.FTPSClient"
$cred = New-Object System.Net.NetworkCredential($username,$password)

"Get DirectoryList"

"Get Files"
$ftp.GetFiles($localFromFTPPath, $false)

"Put Files"
$ftp.PutFiles($localToFTPPath, $remoteDropDir, "*.edi", [AlexPilotti.FTPS.Client.EPatternStyle]::Wildcard, $false, $Null)


Print | posted on Friday, March 25, 2011 1:50 PM