Hello Team ,
I am uploading files to ftp server but due to some reason if file is empty at source then it is throwing me below error
Could you please help me to get this resolve?
Exception calling "Write" with "3" argument(s): "Value cannot be null.
Parameter name: buffer"
At C:\Chetan\Powershell-Scripts\SFTPFileCheck1.10.ps1:256 char:17
- $run.Write($filecontent, 0, $filecontent.Length)
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [], MethodInvocationException
- FullyQualifiedErrorId : ArgumentNullException
Here is the code below :
$ftprequest = [System.Net.FtpWebRequest]::Create("$RemoteLocation1")
$ftprequest = [System.Net.FtpWebRequest]$ftprequest
$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$ftprequest.Credentials = new-object System.Net.NetworkCredential($SFTPUser, $Pass)
$ftprequest.UseBinary = $true
$ftprequest.UsePassive = $true
$ftprequest.EnableSsl = $true
$filecontent = gc -en byte $Source1
$ftprequest.ContentLength = $filecontent.Length
$run = $ftprequest.GetRequestStream()
$run.Write($filecontent, 0, $filecontent.Length)
$run.Close()
$run.Dispose()