A cross-platform add-in for Cake that allows to transfer files to and from remote URLs using curl.
C# PowerShell Shell
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

Cake.Curl

Package Windows Linux
NuGet AppVeyor Travis CI

Cake.Curl is a cross-platform add-in for Cake that allows to transfer files to and from remote URLs using curl.

Cross-platform

Cake.Curl targets the .NET Standard 2.0 and the .NET Framework 4.6. As such, it will run on Linux, macOS and Windows.

Prerequisites

In order to use Cake.Curl, you will need to have a copy of the curl executable for your OS. It doesn't have to be in a specific location; as long as it's included in your PATH environment variable, Cake will find it.

Usage

The purpose of this add-in is to expose the functionality of curl to the Cake DSL by being a very thin wrapper around its command line interface; this means that you can use Cake.Curl in the same way as you would normally use curl, only with a different interface.

Here are a few examples of how some common usage scenarios would look like in a Cake script.

First of all, you need to import Cake.Curl in your build script by using the add-in directive:

#addin Cake.Curl

Downloading Files

Downloading a text file from a remote HTTP server onto the working directory:

Task("Download")
    .Does(() =>
{
    CurlDownloadFile(new Uri("http://host/file.txt"));
});

Downloading a sequence of text files numbered between 1 and 10 from a remote HTTP server onto the working directory:

Task("Download")
    .Does(() =>
{
    CurlDownloadFile(new Uri("http://host/file[1-10].txt"));
});

Downloading a text file from a remote HTTP server onto the working directory and giving it a different name:

Task("Download")
    .Does(() =>
{
    CurlDownloadFile(
        new Uri("http://host/file.txt"),
        new CurlDownloadSettings
        {
            OutputPaths = new FilePath[] { "renamed.txt" }
        });
});

Downloading multiple files concurrently from different servers onto the working directory:

Task("Download")
    .Does(() =>
{
    CurlDownloadFiles(new[]
    {
        new Uri("ftp://host/file.txt"),
        new Uri("ftp://anotherhost/anotherfile.txt"),
        new Uri("http://yetanotherhost/yetanotherfile.txt")
    }
});

Downloading multiple files into specific paths:

Task("Download")
    .Does(() =>
{
    CurlDownloadFiles(
        new[]
        {
            new Uri("ftp://host/file.txt"),
            new Uri("http://anotherhost/anotherfile.txt"),
        }
        new CurlDownloadSettings
        {
            OutputPaths = new FilePath[]
            {
                "some/path/file.txt",
                "some/other/path/anotherfile.txt"
            }
        });
});

Uploading Files

Uploading a local text file to a remote HTTP server:

Task("Upload")
    .Does(() =>
{
    CurlUploadFile("some/file.txt", new Uri("http://host/path"));
});

Uploading a local text file to a remote FTPS server using credentials:

Task("Upload")
    .Does(() =>
{
    CurlUploadFile(
        "some/file.txt",
        new Uri("ftps://host/path"),
        new CurlSettings
        {
            Username = "username",
            Password = "password"
        });
});

Custom HTTP Headers

Transferring a file using a custom HTTP header in the request:

Task("Upload")
    .Does(() =>
{
    CurlUploadFile(
        "some/file.txt",
        new Uri("http://host/path"),
        new CurlSettings
        {
            Headers = new Dictionary<string, string>
            {
                ["X-SomeHeader"] = "SomeValue"
            }
        });
});

Additional Resources

You can find more information about how to use Cake.Curl in the official documentation for these projects:

You can also see Cake.Curl in action in the following videos: