I'm working on a PowerShell script to upload the contents of an entire folder to an FTP location. I'm pretty new to PowerShell with only an hour or two of experience. I can get one file to upload fine but can't find a good solution to do it for all files in the folder. I'm assuming a foreach
loop, but maybe there's a better option?
$source = "c:est"
$destination = "ftp://localhost:21/New Directory/"
$username = "test"
$password = "test"
# $cred = Get-Credential
$wc = New-Object System.Net.WebClient
$wc.Credentials = New-Object System.Net.NetworkCredential($username, $password)
$files = get-childitem $source -recurse -force
foreach ($file in $files)
{
$localfile = $file.fullname
# ??????????
}
$wc.UploadFile($destination, $source)
$wc.Dispose()
See Question&Answers more detail:os