4
4
#include " ftpstorcommand.h"
5
5
#include " sslserver.h"
6
6
#include " dataconnection.h"
7
+ #include " ftpserver.h"
7
8
8
9
#include < QFileInfo>
9
10
#include < QDateTime>
@@ -24,8 +25,8 @@ FtpControlConnection::FtpControlConnection(QObject *parent, QSslSocket *socket,
24
25
isLoggedIn = false ;
25
26
encryptDataConnection = false ;
26
27
socket->setParent (this );
27
- connect (socket, SIGNAL ( readyRead ()) , this , SLOT ( acceptNewData ()) );
28
- connect (socket, SIGNAL ( disconnected ()) , this , SLOT ( deleteLater ()) );
28
+ connect (socket, &QIODevice:: readyRead, this , &FtpControlConnection:: acceptNewData);
29
+ connect (socket, &QAbstractSocket:: disconnected, this , &QObject:: deleteLater);
29
30
currentDirectory = " /" ;
30
31
dataConnection = new DataConnection (certData, this );
31
32
this ->certData = certData;
@@ -36,6 +37,11 @@ FtpControlConnection::~FtpControlConnection()
36
37
{
37
38
}
38
39
40
+ void FtpControlConnection::onFileStored (const QString &filepath) const
41
+ {
42
+ qobject_cast<FtpServer*>(parent ())->onFileStored (filepath);
43
+ }
44
+
39
45
void FtpControlConnection::acceptNewData ()
40
46
{
41
47
if (!socket->canReadLine ()) {
@@ -240,7 +246,7 @@ void FtpControlConnection::processCommand(const QString &entireCommand)
240
246
241
247
void FtpControlConnection::startOrScheduleCommand (FtpCommand *ftpCommand)
242
248
{
243
- connect (ftpCommand, SIGNAL ( reply (QString)) , this , SLOT ( reply (QString)) );
249
+ connect (ftpCommand, &FtpCommand:: reply, this , &FtpControlConnection:: reply);
244
250
245
251
if (!dataConnection->setFtpCommand (ftpCommand)) {
246
252
delete ftpCommand;
@@ -258,7 +264,7 @@ void FtpControlConnection::port(const QString &addressAndPort)
258
264
QRegExp exp (" \\ s*(\\ d+,\\ d+,\\ d+,\\ d+),(\\ d+),(\\ d+)" );
259
265
exp .indexIn (addressAndPort);
260
266
QString hostName = exp .cap (1 ).replace (' ,' , ' .' );
261
- int port = exp .cap (2 ).toInt () * 256 + exp .cap (3 ).toInt ();
267
+ quint16 port = exp .cap (2 ).toUShort () * 256 + exp .cap (3 ).toUShort ();
262
268
dataConnection->scheduleConnectToHost (hostName, port, encryptDataConnection);
263
269
reply (" 200 Command okay." );
264
270
}
@@ -281,7 +287,15 @@ void FtpControlConnection::retr(const QString &fileName)
281
287
282
288
void FtpControlConnection::stor (const QString &fileName, bool appendMode)
283
289
{
284
- startOrScheduleCommand (new FtpStorCommand (this , fileName, appendMode, seekTo ()));
290
+ auto storCommand = new FtpStorCommand (this , fileName, appendMode, seekTo ());
291
+ connect (storCommand,&FtpStorCommand::reply,[this , fileName](const QString &details){
292
+ if (details.startsWith (" 226" ))
293
+ {
294
+ qobject_cast<FtpServer*>(parent ())->onFileStored (toLocalPath (fileName));
295
+ }
296
+
297
+ });
298
+ startOrScheduleCommand (storCommand);
285
299
}
286
300
287
301
void FtpControlConnection::cwd (const QString &dir)
@@ -345,7 +359,7 @@ void FtpControlConnection::quit()
345
359
// If we have a running download or upload, we will wait until it's
346
360
// finished before closing the control connection.
347
361
if (dataConnection->ftpCommand ()) {
348
- connect (dataConnection->ftpCommand (), SIGNAL ( destroyed ()) , this , SLOT ( disconnectFromHost ()) );
362
+ connect (dataConnection->ftpCommand (), &QObject:: destroyed, this , &FtpControlConnection:: disconnectFromHost);
349
363
} else {
350
364
disconnectFromHost ();
351
365
}
@@ -416,9 +430,10 @@ void FtpControlConnection::feat()
416
430
" 211-Features:\r\n "
417
431
" UTF8\r\n "
418
432
" 211 End\r\n "
419
- );
433
+ );
420
434
}
421
435
436
+
422
437
qint64 FtpControlConnection::seekTo ()
423
438
{
424
439
qint64 seekTo = 0 ;
0 commit comments