[Net.ServicePointManager]::ServerCertificateValidationCallback={$true}
$Dir = "C:\temp"
foreach($item in (dir $dir))
{
write-output "————————————–"
$fileName = $item.FullName
write-output $fileName
$ftp = [System.Net.FtpWebRequest]::Create("ftp://temp.com\temp\"+$item.Name)
$ftp = [System.Net.FtpWebRequest]$ftp
$ftp.UsePassive = $true
$ftp.UseBinary = $true
$ftp.EnableSsl = $true
$ftp.Credentials = new-object System.Net.NetworkCredential("xxx","xxx")
$ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$rs = $ftp.GetRequestStream();
$reader = New-Object System.IO.FileStream ($fileName, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::Read)
[byte[]]$buffer = new-object byte[] 4096
[int]$count = 0
do
{
$count = $reader.Read($buffer,0,$buffer.Length)
$rs.Write($buffer,0,$count)
} while ($count -gt 0)
$reader.Close()
$rs.Close()
write-output "+transfer completed"
# $item.Delete()
# write-output "+file deleted"
}
I am getting follwing error -:
+ $rs.Write <<<< ($buffer,0,$count)
+ CategoryInfo : InvalidOperation: (Write:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
i am unable to correct this error.by using this script i was able to upload files on FTP but suddenly it give this type of error can anyone rectify or provide me a better solution for uploading large size file on ftp using ps script.
thanks in advance