I am trying to upload a csv file via FTPS as I need SSL enabled but this code keeps throwing an error message (particularly at line $rs = $ftp.GetRequestStream()
):
$username = "username"
$password = "password"
$Url = "ftp://hosturl"
$filename = "somefile.csv"
$usessl=$true
try {
$uri = New-Object System.Uri($url)
$ftp = [System.Net.FtpWebRequest]::Create($uri)
$ftp = [System.Net.FtpWebRequest]$ftp
$ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$ftp.Credentials = new-object System.Net.NetworkCredential($username, $password)
$ftp.UseBinary = $true
$ftp.UsePassive = $true
$ftp.EnableSsl = $usessl
$content = [System.IO.File]::ReadAllBytes($filename)
$ftp.ContentLength = $content.Length
$rs = $ftp.GetRequestStream()
$rs.Write($content, 0, $content.Length)
'File Uploaded.'
$rs.Close()
$rs.Dispose()
}
catch{
Throw $_
}
Error Message:
Exception calling "GetRequestStream" with "0" argument(s): "System error."