Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ Thumbs.db
*.exe


/build
1 change: 1 addition & 0 deletions QFtpServer/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QCoreApplication>
#include <QSettings>
#include <QFileDialog>
#include <QIntValidator>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
Expand Down
10 changes: 9 additions & 1 deletion QFtpServerCommandLine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
#include <ftpserver.h>
#include <QDebug>
#include <QDateTime>
#include <QRandomGenerator>

QChar getRandomChar()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const int range = 'z'-'a' + 1;
const int randomNumber = QRandomGenerator::global()->bounded(range);
return QChar('a' + randomNumber);
#else
return QChar('a' + (qrand()%('z'-'a')));
#endif
}

QString getRandomString(int n)
Expand All @@ -21,9 +28,10 @@ QString getRandomString(int n)
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// Seed the random numbers.
qsrand(QTime::currentTime().msec());
#endif

const QString &userName = getRandomString(3);
const QString &password = getRandomString(3);
Expand Down
30 changes: 26 additions & 4 deletions QFtpServerLib/ftpcontrolconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <QTimer>
#include <QSslSocket>

#include <QRegularExpression>

FtpControlConnection::FtpControlConnection(QObject *parent, QSslSocket *socket, const QString &rootPath, const QString &userName, const QString &password, bool readOnly) :
QObject(parent)
{
Expand Down Expand Up @@ -137,7 +139,7 @@ QString FtpControlConnection::toLocalPath(const QString &fileName) const
// Note we do this **before** prepending the root path, in order to avoid
// "jailbreaking" out of the "chroot".
QStringList components;
foreach (const QString &component, localPath.split('/', QString::SkipEmptyParts)) {
foreach (const QString &component, localPath.split('/', Qt::SkipEmptyParts)) {
if (component == "..") {
if (!components.isEmpty()) {
components.pop_back();
Expand Down Expand Up @@ -256,10 +258,30 @@ void FtpControlConnection::port(const QString &addressAndPort)
// PORT h1,h2,h3,h4,p1,p2

// Get IP and port.
QString hostName;
int port = 0;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QRegularExpression exp("\\s*(\\d+,\\d+,\\d+,\\d+),(\\d+),(\\d+)");
auto match = exp.match(addressAndPort);
if(match.hasMatch()) {
hostName = match.captured(1).replace(',', '.');
int h = match.captured(2).toInt();
int l = match.captured(3).toInt();
port = h * 256 + l;
}
#else
QRegExp exp("\\s*(\\d+,\\d+,\\d+,\\d+),(\\d+),(\\d+)");
exp.indexIn(addressAndPort);
QString hostName = exp.cap(1).replace(',', '.');
int port = exp.cap(2).toInt() * 256 + exp.cap(3).toInt();
if (exp.indexIn(addressAndPort) != -1) {
QString hostName = exp.cap(1).replace(',', '.');
int h = exp.cap(2).toInt();
int l = exp.cap(3).toInt();
port = h * 256 + l;
}
#endif
if(hostName.isEmpty()) {
reply("address or port invalid!!!");
return;
}
dataConnection->scheduleConnectToHost(hostName, port, encryptDataConnection);
reply("200 Command okay.");
}
Expand Down