Files
taskwarrior-2.x/src/TransportSSH.cpp
Paul Beckingham dab06f8672 Code Cleanup
- All objects now use the same convention for naming members.  The
  consistency is a good thing.
2011-08-25 21:54:28 -04:00

107 lines
3.0 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2010 - 2011, Johannes Schlatow.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#define L10N // Localization complete.
#include <text.h>
#include <i18n.h>
#include <TransportSSH.h>
////////////////////////////////////////////////////////////////////////////////
TransportSSH::TransportSSH(const Uri& uri) : Transport(uri)
{
_executable = "scp";
}
////////////////////////////////////////////////////////////////////////////////
void TransportSSH::send(const std::string& source)
{
if (_uri._host == "")
throw std::string (STRING_TRANSPORT_SSH_URI);
// Is there more than one file to transfer?
// Then path has to end with a '/'
if (is_filelist(source) && !_uri.is_directory())
throw format (STRING_TRANSPORT_URI_NODIR, _uri._path);
// cmd line is: scp [-p port] [user@]host:path
if (_uri._port != "")
{
_arguments.push_back ("-P");
_arguments.push_back (_uri._port);
}
_arguments.push_back (source);
if (_uri._user != "")
{
_arguments.push_back (_uri._user + "@" + _uri._host + ":" + _uri._path);
}
else
{
_arguments.push_back (_uri._host + ":" + _uri._path);
}
if (execute())
throw std::string (STRING_TRANSPORT_SSH_NORUN);
}
////////////////////////////////////////////////////////////////////////////////
void TransportSSH::recv(std::string target)
{
if (_uri._host == "")
throw std::string (STRING_TRANSPORT_SSH_URI);
// Is there more than one file to transfer?
// Then target has to end with a '/'
if (is_filelist(_uri._path) && !is_directory(target))
throw format (STRING_TRANSPORT_URI_NODIR, target);
// cmd line is: scp [-p port] [user@]host:path
if (_uri._port != "")
{
_arguments.push_back ("-P");
_arguments.push_back (_uri._port);
}
if (_uri._user != "")
{
_arguments.push_back (_uri._user + "@" + _uri._host + ":" + _uri._path);
}
else
{
_arguments.push_back (_uri._host + ":" + _uri._path);
}
_arguments.push_back (target);
if (execute())
throw std::string (STRING_TRANSPORT_SSH_NORUN);
}
////////////////////////////////////////////////////////////////////////////////