PowerShell FTP 上传

标签 powershell upload proxy ftp

$infographie="C:\Archive\Infographie\28052013\myfile.pdf"

$ftp = "ftp://174.9.102.210/public_html/infographie/myfile.pdf"

$user = "****"

$pass = "*******"

$webclient = New-Object System.Net.WebClient 

$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  

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

try{

$webclient.UploadFile($uri, $infographie) 

}
catch
{

Write-Host "`nAn Error occured while uploading file to: $Uri"

Throw    
}

我每次都有问题,我尝试执行脚本,我尝试了很多解决方案,但没有一个解决了我的问题
Exception calling "UploadFile" with "2" argument(s): "An exception occurred during
a ebClient request."
At D:\Scripts\test.ps1:14 char:22
+ $webclient.UploadFile <<<< ($uri,$File)
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

当我使用 filezila 时,它似乎使用了 Proxy ixftp.e-i.net:8011 并且它有效,我不知道如何在 PowerShell 中设置代理

最佳答案

我成功地使用了这个脚本(来自 http://gallery.technet.microsoft.com/scriptcenter/80647f66-139c-40a4-bb7a-04a2d73d423c ):

#we specify the directory where all files that we want to upload  
$Dir="C:/Dir"    

#ftp server 
$ftp = "ftp://ftp.server.com/dir/" 
$user = "user" 
$pass = "Pass"  

$webclient = New-Object System.Net.WebClient 

$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  

#list every sql server trace file 
foreach($item in (dir $Dir "*.trc")){ 
    "Uploading $item..." 
    $uri = New-Object System.Uri($ftp+$item.Name) 
    $webclient.UploadFile($uri, $item.FullName) 
 } 

关于PowerShell FTP 上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16807925/

相关文章:

PowerShell DSC 复合资源

c# - 如何获取之前连接的 USB 设备的时间戳?

php - 将新文件名存储在 mysql 数据库中 verot class.upload.php

c# - Image.FromStream(PostedFile.InputStream) 失败。 (参数无效。)(AsyncFileUpload))

proxy - 无法从 socks 中确定 SOCKS 版本

c# - 在 TransactionScope 中调用 Runspace.Open() 会更改 Transaction.Current 并抛出异常

sql - Azure SQL Powershell,如何读取数据 View

php - 拖放文件上传

ssh - Jenkins slave 使用 ssh 网关

php - 当我使用代理时,我收到 502 Bad Gateway