-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.cpp
86 lines (68 loc) · 2.31 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**************************************************************************
**
** This file is part of QSsh
**
** Copyright (c) 2012 LVK
**
** Contact: [email protected]
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
**************************************************************************/
#include <QCoreApplication>
#include <QStringList>
#include <iostream>
#include "securefileuploader.h"
void showSyntax();
QString getPassword();
void upload(const QString &orig, const QString &dest, const QString &passwd);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
if (argc != 3) {
showSyntax();
}
QString orig = QString::fromLocal8Bit(argv[1]);
QString dest = QString::fromLocal8Bit(argv[2]);
QString passwd = getPassword();
upload(orig, dest, passwd);
return a.exec();
}
void showSyntax()
{
std::cerr << "Syntax: " << std::endl;
std::cerr << " SecureUploader local_file username@host:/destination_path" << std::endl;
exit(1);
}
QString getPassword()
{
std::cout << "Password (Warning password will be echoed): ";
std::string passwd;
std::cin >> passwd;
return QString::fromStdString(passwd).trimmed();
}
void upload(const QString &orig, const QString &dest, const QString &passwd)
{
// Parse destination with format "username@host:/destination"
QStringList l1 = dest.split(QLatin1Char('@'));
if (l1.size() == 2) {
QStringList l2 = l1[1].split(QLatin1Char(':'));
if (l2.size() == 2) {
static SecureFileUploader uploader;
uploader.upload(orig, l2[1], l2[0], l1[0], passwd);
} else {
std::cerr << "SecureUploader: Error invalid parameter " << dest.toStdString() << std::endl;
showSyntax();
}
} else {
std::cerr << "SecureUploader: Error invalid parameter " << dest.toStdString() << std::endl;
showSyntax();
}
}