I will like upload a file to SFTP Filezilla but I have an error message and I can not solve my problem
$ftp = "Address"
$Username = "username"
$Password = "password"
$Localdir = "address\test.docx"
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($UserName, $Password)
foreach ($item in (dir $Localdir "*.docx")) {
"Uploading $item..."
$uri = New-Object System.Uri($ftp+$item.Name)
Write-Output $uri,$item.FullName
$webclient.UploadFile($uri, $item.FullName)
}
When I execute my script, I have an error message :
Exception when calling "UploadFile" with "2" argument (s): "An exception occurred during a WebClient request. To the character C: \ Users \ PCA \ Downloads \ powershell \ test4 - to see.ps1: 15: 5 + $ webclient.UploadFile ($ ftp, $ item) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException
How resolve this problem ? (I execute this script with on windows 10 and the version powershell is 5.1)