【发布时间】:2015-10-25 19:28:58
【问题描述】:
我正在使用 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()
【问题讨论】:
标签: .net powershell ftp webclient