Q. How can I FTP using PowerShell?
A. PowerShell has full access to .NET methods which has FTP capabilities however there are PowerShell modules available for download which expose these FTP capabilities as easy to use cmdlets. A great example library to use is available at https://gallery.technet.microsoft.com/scriptcenter/PowerShell-FTP-Client-db6fe0cb. Once you extract to your module path, for example C:\WINDOWS\System32\WindowsPowerShell\v1.0\Modules the module can be loaded and used. Below is an example connection to a FTP server and its contents listed.
Import-Module PSFTP
$FTPServer = 'ftp.host.com'
$FTPUsername = 'username'
$FTPPassword = 'password'
$FTPSecurePassword = ConvertTo-SecureString -String $FTPPassword -asPlainText -Force
$FTPCredential = New-Object System.Management.Automation.PSCredential($FTPUsername,$FTPSecurePassword)
Set-FTPConnection -Credentials $FTPCredential -Server $FTPServer -Session MySession -UsePassive
$Session = Get-FTPConnection -Session MySession
Get-FTPChildItem -Session $Session -Path /htdocs #-Recurse
0 comments
Hide comments