1

I am converting some bash downloader scripts to PowerShell, and I am using Invoke-WebRequest instead of curl to eliminate external dependencies (so curl for Windows is not an option).

Most curl options can be replicated with Invoke-WebRequest but I could not find a way to replicate the behavior of
curl -C - <url> -o <filename>

From the curl manpage:

-C, --continue-at <offset>

Continue/Resume a previous file transfer at the given offset.
The given offset is the exact number of bytes that will be skipped, counting
from the beginning of the source file before it is transferred to the destination.
If used with uploads, the FTP server command SIZE will not be used by curl.

Use "-C -" to tell curl to automatically find out where/how to resume the transfer.
It then uses the given output/input files to figure that out.

If this option is used several times, the last one will be used.

I did check the docs for Invoke-WebRequest but wasn't able to find a matching option.

4
  • 2
    take a look at the ps7 version of Invoke-RestMethod. it has a -Resume parameter that seems likely to do what you want. ///// otherwise, use a windows version curl.exe.
    – Lee_Dailey
    Commented Aug 30, 2020 at 2:33
  • @Lee_Dailey Thanks, that is exactly what I was looking for. Commented Aug 30, 2020 at 2:56
  • So does the bit cmdlets in all PS versions. 'powershell bits cmdlets resume'
    – postanote
    Commented Aug 30, 2020 at 4:04
  • @KartikSoneji - you are most welcome! glad to have helped a little ... [grin]
    – Lee_Dailey
    Commented Aug 30, 2020 at 13:30

1 Answer 1

0

I am also using PowerShell and likewise am a fan of curl's -C - option. After a bit of digging, this turned out to be easier than I thought...

Solution 1: PowerShell: -Resume switch

  • Invoke-WebRequest has a -Resume parameter which works very similar to curl's -C -
  • For more information about -Resume see: Invoke-webrequest -resume
  • NOTE 1: Was introduced in PowerShell 6.1 (so you need to be using pwsh.exe rather than powershell.exe)
  • NOTE 2: Requires the -OutFile parameter

Solution 2: curl in Windows

I appreciate OP's desire not to rely on external CLI's / dependencies, but if using PowerShell 6.1+ is not an option, note that...

  • curl is now included in Windows and is part of Windows 10/11 by default
  • For more information see: curl shipped by Microsoft

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .