将文件夹及其所有子项上载到FTP服务器的Powershell脚本存在多个错误

时间:2013-10-03 09:40:18

标签: powershell azure ftp

您好我发现这个脚本可以帮助我将整个文件夹及其所有嵌套内容复制到我的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.

我如何解决这个问题?

0 个答案:

没有答案