I was tasked with creating a script to check for and download new files from an ftp path to a local path as well as upload any files in a local path to an ftp path. It took a little research to be able to do this. I am somewhat newer to PowerShell. In our process we download the files, build orders out of the files and then they are renamed with a .BUILD extension. The script checks for any files with the .BUILD extension and moves them to a different folder to keep things neat. It also moves any sent files to a different folder after they are sent for backup purposes. The script uses the PSFTP Powershell Module and will need to be imported before use of this script. The script is as follows.
#Use PSFTP Powershell Module
Import-Module PSFTP
#Clear Screen
clear-host
#Variable Declaration
$ftpserver = "FTP SERVER HOSTNAME HERE"
$username = "FTP USER NAME HERE"
$pass = "FTP PASSWORD HERE"
$password = $pass | ConvertTo-SecureString -asPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential($username, $password)
$ftpsend = "REMOTE SEND PATH HERE"
$ftprecv = "REMOTE RECEIVE PATH HERE"
$localsend = "LOCAL SEND PATH HERE"
$localrecv = "LOCAL RECEIVE PATH HERE"
$localsent = "LOCAL SENT PATH HERE"
$localrcvd = "LOCAL RECEIVED PATH HERE"
<#
Build/Connect FTP Server Session (JD is what I called my session, this can be anything. There are multiple different options that can be used here, see PSFTP documentation to see them)
#>
Set-FTPConnection -Credentials $credentials -Server $ftpserver -Session JD -EnableSsl -ignoreCert -UsePassive
#Declare Current Session (JD is what I called my session, this can be anything)
$session = Get-FTPConnection JD
#List/Get Files in FTP path
Get-FTPChildItem -Session $session -Path $ftprecv | Get-FTPItem -Session $session -LocalPath $localrecv
#Send Files to FTP path
Get-ChildItem -Path $localsend -File | Add-FTPItem -Session $session -Path $ftpsend
#Move Sent Files to Local sent
Get-ChildItem -Path $localsend -File | Move-Item -Destination $localsent
#Move Received Files to Local rcvd
Get-ChildItem -Path $localrecv *.BUILD | Move-Item -Destination $localrcvd
PSFTP documentation can be found here: https://gallery.technet.microsoft.com/powershell-ftp-client-db6fe0cb