71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
#include "SFTPServerManager.h"
|
|
#include "GlobalDefine.h"
|
|
|
|
CSFTPServerManager::CSFTPServerManager()
|
|
{
|
|
mEnableSFTPClient = false;
|
|
}
|
|
|
|
int CSFTPServerManager::InitFTPServerManager(bool EnableSFTPClient, QString SFTPLogin, QString SFTPPassword, QString SFTPServerAddress, QString SFTPRemoteDir, QString FilenamePrefix)
|
|
{
|
|
if(EnableSFTPClient == false)
|
|
{
|
|
mEnableSFTPClient = false;
|
|
return RET_OK;
|
|
}
|
|
|
|
mEnableSFTPClient = true;
|
|
mSFTPLogin = SFTPLogin;
|
|
mSFTPPassword = SFTPPassword;
|
|
mSFTPServerAddress = SFTPServerAddress;
|
|
mSFTPRemoteDir = SFTPRemoteDir;
|
|
mFilenamePrefix = FilenamePrefix;
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
int CSFTPServerManager::TransferTrainLogToSFTPServer(QString FileName, bool Detection)
|
|
{
|
|
if(mEnableSFTPClient == false)
|
|
{
|
|
return RET_ERROR;
|
|
}
|
|
|
|
|
|
|
|
QString DestFilePath = FileName;
|
|
if(Detection == true)
|
|
{
|
|
DestFilePath.prepend(mFilenamePrefix + "-D-"); //Flag indiquant que ce passage contient des détections (D)
|
|
}
|
|
else
|
|
{
|
|
DestFilePath.prepend(mFilenamePrefix + "-N-"); //Flag inidiquant un passage normal (sans détection) (N)
|
|
}
|
|
|
|
|
|
DestFilePath.prepend(mSFTPRemoteDir);
|
|
QString OriginFilePath = FileName;
|
|
OriginFilePath.prepend("./Trains/");
|
|
|
|
QString Cmd;
|
|
|
|
#ifdef USE_SCP
|
|
Cmd = QString ("sshpass -p \"%1\" scp %2 %3@%4:%5").arg(mSFTPPassword).arg(OriginFilePath).arg(mSFTPLogin).arg(mSFTPServerAddress).arg(DestFilePath);
|
|
#else
|
|
#endif
|
|
qDebug("%s",qPrintable(Cmd));
|
|
|
|
// mTransferProcess->start(Cmd);
|
|
// mProcessTimer->start(PROCESS_TIMEOUT); //Allow some time to copy the file
|
|
// mNetDriveSMState = NET_DRIVE_TRANSFERRING_TRAIN_LOG_STATE;
|
|
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
void CSFTPServerManager::NewTrainFileSaved(QString Filename, bool Detection)
|
|
{
|
|
TransferTrainLogToSFTPServer(Filename,Detection);
|
|
}
|