hello,
I am a newbie and facing following error while uploading XML files via FTP. Please advise what’s being wrong here.
ERROR:
Exception calling “UploadFile” with “2” argument(s): “An exception occurred during a WebClient request.”
At line:17 char:5
-
$webclient.UploadFile($Uri, $item.FullName)
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: ( , MethodInvocationException
- FullyQualifiedErrorId : WebException
SCRIPT:
#Files to upload
$Dir="D:.…\xmls"
$Backup = "D:.…\xmls\backup_of_errors"
#ftp server
$ftp = “sftp://abc.test.com”
$user = “Username”
$pass = Read-Host ‘Password’ -AsSecureString
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
foreach($item in (dir $Dir “*.xml”)){
“Uploading $item…”
$uri = New-Object System.Uri($ftp+$item.Name)
$webclient.UploadFile($Uri, $item.FullName)
}