Powershell error FTP Upload Script

 I am new to Powershell. I am looking for a script to perform an ftp upload.  I found the script below.   I made changes to the variable values. The variables values below are not mine.  

# Config
$Username = "FTPUSER"
$Password = "Passw0rd"
$LocalFile = "C:\Temp\file.zip"
$RemoteFile = "ftp://thomasmaurer.ch/downloads/files/file.zip"
# 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 download
      do {
            $ReadLength = $ResponseStream.Read($ReadBuffer,0,1024)
      while ($ReadLength -ne 0)

When I run I get the following error shown in the attachment Ftp Powershell errorwhich just keeps repeating.  I guess due to the loop.  The file does not transfer. Please let me know if any additional infomation is needed.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
$responseStream  var is empty.
jverasqlAuthor Commented:
Thank you.  How do I correct this?  Does this mean it cannot find the find locally to transfer?
Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
You do need to open it on PowerShell ISE, set a breakpoint and check it line by line, it's a debug process and make sure the variable is not empty, so it can work the binary part (loop) and continue the progress of the script.
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

You're using the script to download a file.  If you took this code from this website, you can read in the comments below the post that the author made a typo, however, you can also see in the code you're using that the FTPWebRequest method is DownloadFile.

Use this code instead:
# Config
$Username = "FTPUSER"
$Password = "P@assw0rd"
$LocalFile = "C:\Temp\file.zip"
$RemoteFile = "ftp://thomasmaurer.ch/downloads/files/file.zip"

# Create FTP Rquest Object
$FTPRequest = [System.Net.FtpWebRequest]::Create("$RemoteFile")
$FTPRequest = [System.Net.FtpWebRequest]$FTPRequest
$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$FTPRequest.Credentials = new-object System.Net.NetworkCredential($Username, $Password)
$FTPRequest.UseBinary = $true
$FTPRequest.UsePassive = $true
# Read the File for Upload
$FileContent = gc -en byte $LocalFile
$FTPRequest.ContentLength = $FileContent.Length
# Get Stream Request by bytes
$Run = $FTPRequest.GetRequestStream()
$Run.Write($FileContent, 0, $FileContent.Length)
# Cleanup

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jverasqlAuthor Commented:
I apologize for the delay.  The Expert Comment by:dsuyemoto is very helpful.  Please keep open I will try the solution and respond ASAP next day or two.

Again, I apologize.  

Thank you.
Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.