Continuously upload files to FTP using PowerShell

Sometimes we need to continuously upload files to FTP from local disk. We can do it using the following PowerShell Script.

import-module NetCmdlets
$i=5
while ($i -eq 5){
new-item c:\wgrywam -itemtype directory
Get-ChildItem C:\CB08 -Recurse |? {$_.LastWriteTime -le (get-date).AddMinutes(-3)} |% {move-item $_.Fullname c:\wgrywam}
Get-ChildItem C:\wgrywam -Recurse |% {send-ftp -server ftp.pol.pl -user uzytkownik -password haslo -localfile $_.Fullname -remotefile $_.name}
#Get-ChildItem C:\wgrywam -Recurse | % { remove-item $_.Fullname }
Remove-Item -Recurse -Force c:\wgrywam
}

So this script simply create temporary directory c:\wgrywam, move to it all files older than 3 minutes from C:\CB08 -Recurse. After that connect to ftp.pol.pl, using username user uzytkownik and password haslo and put there all files from temporary (c:\wgrywam) directory. Finally remove temporary (c:\wgrywam) directory.

To use this you need to install NetCmdlets  from here.