Added the new backendtool cli project
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{2AF960C0-357D-4D44-A3D5-8B6E89DB0F11}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Duplicati.CommandLine.BackendTool</RootNamespace>
|
||||
<AssemblyName>Duplicati.CommandLine.BackendTool</AssemblyName>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>..\Duplicati.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Library\Backend\CloudFiles\Duplicati.Library.Backend.CloudFiles.csproj">
|
||||
<Project>{1BFAE226-8364-4086-825C-BB83F6F3EE4C}</Project>
|
||||
<Name>Duplicati.Library.Backend.CloudFiles</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Library\Backend\File\Duplicati.Library.Backend.File.csproj">
|
||||
<Project>{FC9B7611-836F-4127-8B44-A7C31F506807}</Project>
|
||||
<Name>Duplicati.Library.Backend.File</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Library\Backend\FTP\Duplicati.Library.Backend.FTP.csproj">
|
||||
<Project>{F61679A9-E5DE-468A-B5A4-05F92D0143D2}</Project>
|
||||
<Name>Duplicati.Library.Backend.FTP</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Library\Backend\GoogleDocs\Duplicati.Library.Backend.GoogleDocs.csproj">
|
||||
<Project>{42C91180-11EB-4590-82EA-80FE9D4DEBEC}</Project>
|
||||
<Name>Duplicati.Library.Backend.GoogleDocs</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Library\Backend\S3\Duplicati.Library.Backend.S3.csproj">
|
||||
<Project>{C03F6DFD-805A-4BE0-9338-64870ADDB4A2}</Project>
|
||||
<Name>Duplicati.Library.Backend.S3</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Library\Backend\SkyDrive\Duplicati.Library.Backend.SkyDrive.csproj">
|
||||
<Project>{CCD76347-7DC7-4B42-B7E1-E500E624CAC3}</Project>
|
||||
<Name>Duplicati.Library.Backend.SkyDrive</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Library\Backend\SSHv2\Duplicati.Library.Backend.SSHv2.csproj">
|
||||
<Project>{FF2BF37C-E502-4C98-BEA0-701671DDFA08}</Project>
|
||||
<Name>Duplicati.Library.Backend.SSHv2</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Library\Backend\TahoeLAFS\Duplicati.Library.Backend.TahoeLAFS.csproj">
|
||||
<Project>{C0270709-2A40-43B5-8CF1-69581B9FA2A1}</Project>
|
||||
<Name>Duplicati.Library.Backend.TahoeLAFS</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Library\Backend\WEBDAV\Duplicati.Library.Backend.WEBDAV.csproj">
|
||||
<Project>{BAE27510-8B5D-44B2-B33E-372A98908041}</Project>
|
||||
<Name>Duplicati.Library.Backend.WEBDAV</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Library\DynamicLoader\Duplicati.Library.DynamicLoader.csproj">
|
||||
<Project>{0CA86ECF-5BEC-4909-B4F6-110A03B30B92}</Project>
|
||||
<Name>Duplicati.Library.DynamicLoader</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Library\Interface\Duplicati.Library.Interface.csproj">
|
||||
<Project>{C5899F45-B0FF-483C-9D38-24A9FCAAB237}</Project>
|
||||
<Name>Duplicati.Library.Interface</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Library\Utility\Duplicati.Library.Utility.csproj">
|
||||
<Project>{DE3E5D4C-51AB-4E5E-BEE8-E636CEBFBA65}</Project>
|
||||
<Name>Duplicati.Library.Utility</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,151 @@
|
||||
#region Disclaimer / License
|
||||
// Copyright (C) 2011, Kenneth Skovhede
|
||||
// http://www.hexad.dk, opensource@hexad.dk
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//
|
||||
#endregion
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Duplicati.Library.Interface;
|
||||
|
||||
namespace Duplicati.CommandLine.BackendTool
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static int Main(string[] _args)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<string> args = new List<string>(_args);
|
||||
Dictionary<string, string> options = Library.Utility.CommandLineParser.ExtractOptions(args);
|
||||
|
||||
if (!options.ContainsKey("ftp_password") && !string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("FTP_PASSWORD")))
|
||||
options["ftp_password"] = System.Environment.GetEnvironmentVariable("FTP_PASSWORD");
|
||||
|
||||
if (!options.ContainsKey("ftp_username") && !string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("FTP_USERNAME")))
|
||||
options["ftp_username"] = System.Environment.GetEnvironmentVariable("FTP_USERNAME");
|
||||
|
||||
if (options.ContainsKey("tempdir") && !string.IsNullOrEmpty(options["tempdir"]))
|
||||
Library.Utility.TempFolder.SystemTempPath = options["tempdir"];
|
||||
|
||||
|
||||
string command = null;
|
||||
if (args.Count >= 2)
|
||||
{
|
||||
if (args[0].Equals("list", StringComparison.InvariantCultureIgnoreCase))
|
||||
command = "list";
|
||||
else if (args[0].Equals("get", StringComparison.InvariantCultureIgnoreCase))
|
||||
command = "get";
|
||||
else if (args[0].Equals("put", StringComparison.InvariantCultureIgnoreCase))
|
||||
command = "put";
|
||||
else if (args[0].Equals("delete", StringComparison.InvariantCultureIgnoreCase))
|
||||
command = "delete";
|
||||
else if (args[0].Equals("create-folder", StringComparison.InvariantCultureIgnoreCase))
|
||||
command = "create";
|
||||
}
|
||||
|
||||
|
||||
if (args.Count >= 2 || args[0].ToLower() == "help" || args[0] == "?" || command == null)
|
||||
{
|
||||
if (command == null && args.Count >= 2)
|
||||
{
|
||||
Console.WriteLine("Unsupported command: {0}", args[0]);
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
Console.WriteLine("Usage: <command> <protocol>://<username>:<password>@<path> [filename]");
|
||||
Console.WriteLine("Example: LIST ftp://user:pass@server/folder");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Supported backends: " + string.Join(",", Duplicati.Library.DynamicLoader.BackendLoader.Keys));
|
||||
Console.WriteLine("Supported commands: GET PUT LIST DELETE CREATEFOLDER");
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
using(var backend = Library.DynamicLoader.BackendLoader.GetBackend(args[1], options))
|
||||
{
|
||||
if (backend == null)
|
||||
throw new Exception("Backend not supported");
|
||||
|
||||
if (command == "list")
|
||||
{
|
||||
if (args.Count != 2)
|
||||
throw new Exception(string.Format("too many arguments: {0}", string.Join(",", args)));
|
||||
Console.WriteLine(string.Format("{0}\t{1}\t{2}\t{3}", "Name", "Dir/File", "LastChange", "Size"));
|
||||
|
||||
foreach(var e in backend.List())
|
||||
Console.WriteLine(string.Format("{0}\t{1}\t{2}\t{3}", e.Name, e.IsFolder ? "Dir" : "File", e.LastModification, e.Size < 0 ? "" : Library.Utility.Utility.FormatSizeString(e.Size)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (command == "create")
|
||||
{
|
||||
if (args.Count != 2)
|
||||
throw new Exception(string.Format("too many arguments: {0}", string.Join(",", args)));
|
||||
|
||||
if (!(backend is IBackend_v2))
|
||||
throw new Exception(string.Format("{0} backend does not support creating folders", backend.ProtocolKey));
|
||||
((IBackend_v2)backend).CreateFolder();
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (command == "delete")
|
||||
{
|
||||
if (args.Count < 3)
|
||||
throw new Exception("DELETE requires a filename argument");
|
||||
if (args.Count > 3)
|
||||
throw new Exception(string.Format("too many arguments: {0}", string.Join(",", args)));
|
||||
backend.Delete(args[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (command == "get")
|
||||
{
|
||||
if (args.Count < 3)
|
||||
throw new Exception("GET requires a filename argument");
|
||||
if (args.Count > 3)
|
||||
throw new Exception(string.Format("too many arguments: {0}", string.Join(",", args)));
|
||||
backend.Get(args[2], args[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (command == "put")
|
||||
{
|
||||
if (args.Count < 3)
|
||||
throw new Exception("PUT requires a filename argument");
|
||||
if (args.Count > 3)
|
||||
throw new Exception(string.Format("too many arguments: {0}", string.Join(",", args)));
|
||||
if (System.IO.File.Exists(args[2]))
|
||||
throw new Exception("File already exists, not overwriting!");
|
||||
|
||||
backend.Put(args[2], args[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
throw new Exception("Internal error");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Command failed: " + ex.Message);
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright (C) 2011, Kenneth Skovhede
|
||||
|
||||
// http://www.hexad.dk, opensource@hexad.dk
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 2.1 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("Duplicati.CommandLine.BackendTool")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
Reference in New Issue
Block a user