我正在编写一个PowerShell脚本,将整个文件夹的内容上传到FTP位置。我对PowerShell非常新,并且只有一两个小时的经验。我可以成功上传一个文件,但找不到一个好的解决方案来处理文件夹中的所有文件。我假设使用foreach
循环,但也许还有更好的选择?
$source = "c:\test"
$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()