I would like to use WebRequest class upload to remote secure ftp site and have tried using Webclient but getting all sort of exception.
Suffice tosay that I have successfully use Filezilla to connect and upload file the remote but would like to use powershell to automate the process.
Client server has windows 2008 R2 standard - powershell version is 2.0
here is the code I ran and below it is the exception I now get
#setup permission + working dir
$user = "ftpclient"
$password = "****"
$localdir = "C:/Extracts/foldern/"
$ftpdir = "ftps://100.100.100.0:900/Outbound"
###########################
$client = New-Object System.Net.WebClient
$client.Credentials = New-Object System.Net.NetworkCredential($user,$password)
foreach($item in Get-ChildItem -recurse $localdir)
{
$filename = [system.io.path]::GetFullPath($item.FullName).SubString([system.io.path]::GetFullPath($localdir).Length + 1)
Write-Host "Send $item..."
$file = New-Object System.Uri($ftpdir+"/"+$filename)
$client.UploadFile($file, $item.FullName)
}
Transfert de EDI_CIG_OrbitExtract.zip...
Exception calling "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request."
At line:5 char:31
+ $client.UploadFile <<<< ($file, $item.FullName)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
I have read somewhere about using Webrequest instead of Webclient but dont know how.
any assistance is greatly appreciated