您好,我发现此脚本可帮助我将包含所有嵌套内容的整个文件夹复制到我的 FTP 服务器,该服务器是 Azure 托管的 Windows Server 2012。
这是脚本:
$a = (Get-Host).UI.RawUI
$a.WindowTitle = "Sync Folder To Ftp"
$ftp = "ftp://igtestvm1.cloudapp.net/IQS FTP Content/IQSWS"
$localDirectory = "C:\TeamCity\buildAgent\work\8b19187411566286\IQS Web Server"
$user = "u"
$pass = "p"
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
$webclient.UsePassive = $False
$Files = get-childitem $localDirectory -recurse -force
foreach ($File in $Files)
{
$LocalFile = $File.FullName
$RemoveDirectory = $LocalFile.Replace($localDirectory,"")
$ChangeSlashes = $RemoveDirectory.Replace('\', '/')
$RemoveSpaces = $ChangeSlashes.Trim()
$RemoteFile = $ftp+$RemoveSpaces
$uri = New-Object System.Uri($RemoteFile)
$webclient.UploadFile($uri, $LocalFile)
Write-Host "Getting $File from $localDirectory" -Foreground "Red"
Write-Host "Puting $File to $ftp" -Foreground "Yellow"
}
Write-Host "Finished Sync to $ftp" -Foreground "Green"
现在,当我运行脚本时出现以下错误:
Property 'UsePassive' cannot be found on this object; make sure it exists and is settable
Exception calling "UploadFile" with "2" argument(s): "The remote server returned an error: 227 Entering Passive Mode
Exception calling "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request.
我将如何解决这个问题?