$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
}
I have problem each time, i try to execute the script, i've tried many solutions but none of them solved my problem
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
When i use filezila it seems to use Proxy ixftp.e-i.net:8011 and it works, i don't know how to set up the proxy in PowerShell
I've used this script with success:
#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)
}