update: here's an updated function for uploading an entire directory tree:
Original Post:
ckj asked me how to "recursively upload a directory mutiple levels deep via send-ftp". Here is my answer:
For now, the send-ftp cmdlet allows you to upload one file at a time (its a beta). But you can easily use get-children's recursive flag to get a list of all the files to upload, and call send-ftp for each one. Here is a little script to do so.
param( [string] $dir = "C:\Testing\FTPTest\" )
$files = (get-childitem $dir -r)
foreach ($file in $files) {
$remfilename = $file.FullName.Replace($dir, "")
$remfilename = $remfilename.Replace("\", "/")
if ($file.Attributes -eq "Directory") {
send-ftp -server MYSERVER -user TEST -password TEST -create $remfilename
}
else {
send-ftp -server MYSERVER -user TEST -password TEST -localfile $file.FullName -remotefile $remfilename
}
Write-Host $remfilename
}
Technorati : FTP, Netcmdlets, cmdlets, powershell