错误:Webclient请求(FTP)期间发生异常 - Powershell 2.0

时间:2011-09-28 08:21:08

标签: powershell

我尝试使用此示例,我从这里的帖子中得到: 我正在使用powershell 2.0

$File = "D:\28.csv"
$ftp = "ftp://username:Pwd@IPAddress/in/28.csv"

"ftp url: $ftp"

$webclient = New-Object System.Net.WebClient
$uri = New-Object System.Uri($ftp)

"Uploading $File..."

$webclient.UploadFile($uri,$File)

我正在尝试将文件上传到FTP服务器 但我不断收到错误:

Exception calling "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request."
At D:\Scripts\test.ps1:14 char:22
+ $webclient.UploadFile <<<< ($uri,$File)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

1 个答案:

答案 0 :(得分:1)

它将接受一个字符串作为第一个参数以及System.Uri:

UploadFile方法byte [] UploadFile(字符串地址,字符串fileName)

你可以试试这个:

$webclient.UploadFile($ftp,$File)

发布后发表您的评论 - 您应该编辑您的问题以包含该信息。

看看这个:

http://mycodetrip.com/2008/10/29/fix-for-error-the-requested-ftp-command-is-not-supported-when-using-http-proxy_118/

要点:

  

经过一番调查后,我发现错误发生了   因为SQL Server的方法调用试图使用   服务器机器上的HttpProxy。如果代理未设置为null   显式地在你的代码中,你会得到这个错误。