Resume FTP file copy

Welcome Forums General PowerShell Q&A Resume FTP file copy

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
2 years ago.

  • Author
    Posts
  • #61090

    Participant
    Points: 0
    Rank: Member

    Hi

    I have been having problems downloading a file from a FTP site – it keeps on timing out. I am currently trying the following code:

    $downloadRequest = [Net.WebRequest]::Create($fileUrl)
    $downloadRequest.Method = [System.Net.WebRequestMethods+FTP]::DownloadFile
    $downloadRequest.Credentials = $credentials

    $downloadResponse = $downloadRequest.GetResponse()
    $sourceStream = $downloadResponse.GetResponseStream()
    $targetStream = [System.IO.File]::Create($localFilePath)
    $buffer = New-Object byte[] 10240
    while (($read = $sourceStream.Read($buffer, 0, $buffer.Length)) -gt 0)
    {
    $targetStream.Write($buffer, 0, $read);
    $sourceStream
    $targetStream

    }
    $targetStream.Dispose()
    $sourceStream.Dispose()
    $downloadResponse.Dispose()

    I have changed both Timeout and ReadWriteTimeout values but this made no difference. Possibly a setting on the source server?

    Anyway – is there a way to resume the download once it has timed out?

    Thanks
    Paul

  • #61237

    Keymaster
    Points: 1,759
    Helping HandTeam Member
    Rank: Community Hero

    Not using that class, no. I'd –strongly– suggest you look at BITS, the Background Intelligent Transfer Service, and its associated PowerShell cmdlets. It's designed for this specific purpose.

  • #61363

    Participant
    Points: 0
    Rank: Member

    Thanks – will look at this.

The topic ‘Resume FTP file copy’ is closed to new replies.