2012-08-19 75 views
1

我試圖使用powershell從指定的URL中獲取圖像並將其重新發送到ftp。 但它不以這種方式工作:/將Powershell URL圖像傳輸到FTP

$url = "http://somesite.com/image.jpg" 
$ftp = "ftp://username:[email protected]/folder/image.jpg" 

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

$webclient.UploadFile($uri, $url) 

任何提示嗎? Thanx!

回答

1

.NET中的WebClient和FtpWebRequest類(以及PowerShell)不支持File eXchange Protocol (FXP) - 因此,您需要先將源文件下載到您的計算機,然後通過FTP將文件傳輸到目標:

$source = "http://somesite.com/image.jpg" 
$destination = "ftp://username:[email protected]/folder/image.jpg" 

$webclient = New-Object System.Net.WebClient 

$webclient.DownloadFile($source, "temp.jpg") 
$webclient.UploadFile($destination, "temp.jpg") 
+0

Splendid!非常感謝! :) – 45RPM 2012-08-19 22:26:02