Powershell error FTP Upload Script

Hello,
 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)
            $LocalFileFile.Write($ReadBuffer,0,$ReadLength)
      }
      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.
jverasqlAsked:
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 CEE Solution Guide - CEO Faru Bonon ITCommented:
$responseStream  var is empty.
0
jverasqlAuthor Commented:
Thank you.  How do I correct this?  Does this mean it cannot find the find locally to transfer?
0
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
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.
0
INTRODUCING: WatchGuard's New MFA Solution

WatchGuard is proud to announce the launch of AuthPoint, a powerful, yet simple, Cloud-based MFA service designed to eliminate the vulnerabilities that put your data, systems, and users at risk.

dsuyemotoCommented:
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
$Run.Close()
$Run.Dispose()

Open in new window

0

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.
0
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
Answered
0
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
Powershell

From novice to tech pro — start learning today.