Troubleshooting Question
Per suggestion from "Alex [***Alex140181***] " I am attempting using a powershell script to automate an FTP download.This is to download files, regularly which may update throughout the day, but which will always have the following naming convention "YYMMDD.asc"I attempted to run using the sample at the link provided,https://www.thomasmaurer.ch/2010/11/powershell-ftp-upload-and-download/ but I am afraid I am just too new to this to see what I am doing wrong...I receive a "You cannot call a method on a null-valued expression. At D:\[..].ps1.23 char:1 +$LocalFileFile.Write($ReadBuffer,0,$ReadLength)and $ResponseStream.Read($ReadBuffer0,1024)"See attached Image"
Script is below# Config$Username = "<username>"$Password = "<password>"$LocalFile = "<Local path>\@Y@M@D.asc"$RemoteFile = "<ftp site>/filename.asc" # Create a FTPWebRequest$FTPRequest = [System.Net.FtpWebRequest]::Create($RemoteFile)$FTPRequest.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile$FTPRequest.UseBinary = $true$FTPRequest.KeepAlive = $false# Send the ftp request$FTPResponse = $FTPRequest.GetResponse()# Get a download stream from the server response$ResponseStream = $FTPResponse.GetResponseStream()# Create the target file on the local system and the download buffer$LocalFileFile = New-Object IO.FileStream ($LocalFile,[IO.FileMode]::Create)[byte[]]$ReadBuffer = New-Object byte[] 1024# Loop through the downloaddo {$ReadLength = $ResponseStream.Read($ReadBuffer,0,1024)$LocalFileFile.Write($ReadBuffer,0,$ReadLength)}while ($ReadLength -ne 0)