2011-09-28 36 views
3

我使用此示例我從這裏後得到了嘗試,如: 我使用PowerShell 2.0錯誤:Web客戶端請求(FTP)期間出現的異常 - PowerShell 2.0中

$File = "D:\28.csv" 
$ftp = "ftp://username:[email protected]/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 
+0

我捕獲錯誤及其sayon​​g 「的請求的FTP命令是使用HTTP代理時,機器人的支持」。 任何想法? – naijacoder

回答

1

它將接受一個字符串作爲第一個參數,以及的System.Uri:

UploadFile方法的byte [] UploadFile(字符串的地址,字符串文件名)

你可以試試這個:

$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/

要點:

After a bit of investigation, I found that the error was happening because the method call from SQL Server was attempting to use the HttpProxy on the Server machine. If the proxy is not set to null explicitly in your code, then you will get this error.

+0

確定的答案。您可能希望明確包含代碼行解決方案的要點,以防鏈接發生衝突。 – ajk

+0

@ajk好點 – Matt

+0

感謝傢伙,但沒有在我的代碼中設置代理。林正在使用不同的方法 – naijacoder