#include "StdAfx.h"
|
#include "FTPThreadPool.h"
|
|
|
CFTPThreadPool::CFTPThreadPool(int nType, DWORD dwPeriod) : CTimerThreadPools(dwPeriod, 1), m_nType(nType)
|
{
|
m_pConnection = NULL;
|
m_pFileFind = NULL;
|
m_pSession = NULL;
|
m_bConnect = FALSE;
|
m_nCurLogIndex = 0;
|
|
m_strIP = _T("127.0.0.1");
|
m_strID = _T("ID_Invalid");
|
m_strPassword = _T("PW_Invalid");
|
m_nPort = 21;
|
m_bPassive = TRUE;
|
m_nConnectionTimeout = 5000;
|
|
m_strDefaultFolderPath = _T("/Test/");
|
m_strLastErrorMessage = _T("");
|
|
// [C-PRJ] Image Upload Define - KHT (2020/11/19)
|
m_strIP2 = _T("127.0.0.1");
|
m_strID2 = _T("ID_Invalid");
|
m_strPassword2 = _T("PW_Invalid");
|
m_nPort2 = 21;
|
m_nConnectionTimeout2 = 5000;
|
m_strDefaultFolderPath2 = _T("/Test/");
|
|
//201218 CJH - Download�� IP �߰�
|
m_strIP3 = _T("127.0.0.1");
|
m_strID3 = _T("ID_Invalid");
|
m_strPassword3 = _T("PW_Invalid");
|
m_nPort3 = 21;
|
m_nConnectionTimeout3 = 5000;
|
m_strDefaultFolderPath3 = _T("/Test/");
|
|
m_nCompletCount = 0;
|
m_nProcessCount = 0;
|
m_nTotalCount = 0;
|
|
m_bSharedFolder = TRUE;
|
|
m_bWSIChk = FALSE;
|
|
CreatePathDir(LOCAL_SIGNAL_FILE_PATH);
|
}
|
|
CFTPThreadPool::~CFTPThreadPool(void)
|
{
|
Disconnect();
|
}
|
|
BOOL CFTPThreadPool::StartThread()
|
{
|
return CTimerThreadPools::StartThread();
|
}
|
|
void CFTPThreadPool::StopThread()
|
{
|
CTimerThreadPools::StopThread();
|
}
|
|
BOOL CFTPThreadPool::AddUploadParam( const CFTPUploadParam& uploadParam )
|
{
|
CSingleLock localLock(&m_csUploadList);
|
localLock.Lock();
|
if(uploadParam.m_bFirstPriority==1)
|
{
|
m_deqUploadList.push_front(uploadParam);
|
}
|
else
|
{
|
m_deqUploadList.push_back(uploadParam);
|
}
|
m_nTotalCount = (++m_nTotalCount) % INT_MAX;
|
localLock.Unlock();
|
|
return TRUE;
|
}
|
|
void CFTPThreadPool::TimerThreadProcess( PVOID pParameter )
|
{
|
CSingleLock localLock(&m_csUploadList);
|
localLock.Lock();
|
|
// size check
|
if (m_deqUploadList.size()<1)
|
{
|
localLock.Unlock();
|
return;
|
}
|
|
// get front
|
DeqFTPUploadParamIt it=m_deqUploadList.begin();
|
CFTPUploadParam param = *it;
|
|
// delete front
|
m_deqUploadList.pop_front();
|
localLock.Unlock();
|
|
// ftp process
|
m_nProcessCount++;
|
if (param.m_nProcessType==FTPProcessType_UpFile)
|
{
|
Process_Upload(param);
|
}
|
else
|
{
|
Process_Download(param);
|
}
|
m_nProcessCount--;
|
m_nCompletCount = (++m_nCompletCount) % INT_MAX;
|
|
return;
|
}
|
|
BOOL CFTPThreadPool::Process_UploadAck(int nResultCode, const CFTPUploadParam& uploadParam)
|
{
|
// if (uploadParam.m_nSendResultCode==0)
|
// {
|
// return TRUE;
|
// }
|
|
//HWND hWnd = uploadParam.GetSenderWnd();
|
HWND hWnd = ::FindWindow(NULL, "ReviewSystem");
|
if (hWnd==NULL)
|
{
|
return FALSE;
|
}
|
|
CFTPCopyDataParam ackParam = uploadParam;
|
ackParam.m_nSendResultCode = nResultCode;
|
|
USES_CONVERSION;
|
COPYDATASTRUCT cds;
|
cds.dwData = COPYDATA_RAW_UPLOAD_ACK;
|
cds.cbData = sizeof(CFTPCopyDataParam);
|
cds.lpData = &ackParam;
|
|
DWORD dwReturn = 0;
|
if(SendMessageTimeout(hWnd, WM_COPYDATA, NULL, (LPARAM)&cds, SMTO_NORMAL, 20000, (PDWORD_PTR)(dwReturn)) == FALSE)
|
{
|
return FALSE;
|
}
|
|
return TRUE;
|
}
|
|
BOOL CFTPThreadPool::Process_DownloadAck(int nResultCode, const CFTPUploadParam& uploadParam)
|
{
|
if (uploadParam.m_nSendResultCode==0)
|
{
|
return TRUE;
|
}
|
|
HWND hWnd = uploadParam.GetSenderWnd();
|
if (hWnd==NULL)
|
{
|
return FALSE;
|
}
|
|
CFTPCopyDataParam ackParam = uploadParam;
|
ackParam.m_nSendResultCode = nResultCode;
|
|
USES_CONVERSION;
|
COPYDATASTRUCT cds;
|
cds.dwData = COPYDATA_RAW_DOWNLOAD_ACK;
|
cds.cbData = sizeof(CFTPCopyDataParam);
|
cds.lpData = &ackParam;
|
|
DWORD dwReturn = 0;
|
if(SendMessageTimeout(hWnd, WM_COPYDATA, NULL, (LPARAM)&cds, SMTO_NORMAL, 20000, (PDWORD_PTR)(dwReturn)) == FALSE)
|
{
|
return FALSE;
|
}
|
|
return TRUE;
|
}
|
|
BOOL CFTPThreadPool::Process_Upload( CFTPUploadParam& uploadParam )
|
{
|
CSingleLock localLock(&m_csFtpProcess);
|
m_csFtpProcess.Lock();
|
|
CString strHomePath = _T("");
|
|
// 1. connect
|
CString strMessage = _T("");
|
|
DWORD dwTick = GetTickCount();
|
BOOL bConnect = ConnectMain();
|
dwTick = GetTickCount() - dwTick;
|
strMessage.Format(_T("Connection Time: %d msec"), dwTick);
|
DisplayLogMessage(strMessage);
|
|
int nUploadResult = FALSE;
|
|
if(bConnect)
|
{
|
// 2. upload
|
dwTick = GetTickCount();
|
if( nUploadResult = Upload(uploadParam) )
|
{
|
dwTick = GetTickCount() - dwTick;
|
strMessage.Format(_T("Upload Time: %d msec"), dwTick);
|
DisplayLogMessage(strMessage);
|
}
|
|
// 3. disconnect
|
dwTick = GetTickCount();
|
Disconnect();
|
dwTick = GetTickCount() - dwTick;
|
strMessage.Format(_T("Disconnect Time: %d msec"), dwTick);
|
DisplayLogMessage(strMessage);
|
}
|
|
// ACK�� �ؾ��ϳ�?
|
Process_UploadAck(nUploadResult, uploadParam);
|
|
return TRUE;
|
}
|
|
BOOL CFTPThreadPool::Process_Download( CFTPUploadParam& downloadParam )
|
{
|
CSingleLock localLock(&m_csFtpProcess);
|
m_csFtpProcess.Lock();
|
|
CString strMessage = _T("");
|
|
// 1. connect
|
DWORD dwTick = GetTickCount();
|
BOOL bConnect = ConnectMain();
|
dwTick = GetTickCount() - dwTick;
|
strMessage.Format(_T("Connection Time: %d msec"), dwTick);
|
DisplayLogMessage(strMessage);
|
|
BOOL bResult = TRUE;
|
if(bConnect)
|
{
|
// 2. download
|
dwTick = GetTickCount();
|
if( bResult=Download( downloadParam ) )
|
{
|
dwTick = GetTickCount() - dwTick;
|
strMessage.Format(_T("Download Time: %d msec"), dwTick);
|
DisplayLogMessage(strMessage);
|
}
|
|
// 3. disconnect
|
dwTick = GetTickCount();
|
Disconnect();
|
dwTick = GetTickCount() - dwTick;
|
strMessage.Format(_T("Disconnect Time: %d msec"), dwTick);
|
DisplayLogMessage(strMessage);
|
}
|
|
// ACK�� �ؾ��ϳ�?
|
Process_DownloadAck(TRUE, downloadParam);
|
|
return TRUE;
|
}
|
|
|
void CFTPThreadPool::SetConnectionTimeout( int nTimeout )
|
{
|
m_nConnectionTimeout = nTimeout;
|
}
|
|
void CFTPThreadPool::SetConnectionInfo( CString strIP, CString strUserID, CString strPassword, int nPort, int nTimeout, CString strHomePath, CString strIP2, CString strUserID2, CString strPassword2, int nPort2, int nTimeout2, CString strHomePath2, CString strIP3, CString strUserID3, CString strPassword3, int nPort3, int nTimeout3, CString strHomePath3, BOOL bPassive ,BOOL bWSIChk, BOOL bBDIStackDown)
|
{
|
m_strIP = strIP;
|
m_strID = strUserID;
|
m_strPassword = strPassword;
|
m_nPort = nPort;
|
m_nConnectionTimeout = nTimeout;
|
m_strDefaultFolderPath = strHomePath;
|
m_bPassive = bPassive;
|
|
// [C-PRJ] Image Upload Define - KHT (2020/11/19)
|
m_strIP2 = strIP2;
|
m_strID2 = strUserID2;
|
m_strPassword2 = strPassword2;
|
m_nPort2 = nPort2;
|
m_nConnectionTimeout2 = nTimeout2;
|
m_strDefaultFolderPath2 = strHomePath2;
|
|
//201218 CJH - Download�� IP �߰�
|
m_strIP3 = strIP3;
|
m_strID3 = strUserID3;
|
m_strPassword3 = strPassword3;
|
m_nPort3 = nPort3;
|
m_nConnectionTimeout3 = nTimeout3;
|
m_strDefaultFolderPath3 = strHomePath3;
|
|
m_bWSIChk = bWSIChk;
|
m_bBDIStackDown = bBDIStackDown;
|
|
if(m_strDefaultFolderPath.Right(1) != _T("\\"))
|
{
|
m_strDefaultFolderPath += _T("\\");
|
}
|
|
// if(m_strDefaultFolderPath3.Right(1) != _T("\\"))
|
// {
|
// m_strDefaultFolderPath3 += _T("\\");
|
// }
|
}
|
|
BOOL CFTPThreadPool::ConnectMain()
|
{
|
Sleep(10);
|
|
// Main ���� ����
|
if(m_bConnect = Connect())
|
{
|
//NotifyMessageToParent(eFTPConnection,m_strIP,m_strDefaultFolderPath);
|
// �⺻ ���� �̵�
|
if(m_bSharedFolder == FALSE && ChangeDirectory(m_strDefaultFolderPath) == FALSE)
|
{
|
CString strError = _T("CFTPThread::OnStartUploadProcess ChangeDirectory Process Error");
|
CString strErrorProcess = _T("FTP Chnage Home Path Fail!");
|
//NotifyMessageToParent(eFTPError,strErrorProcess,strError, TRUE);
|
|
if(m_bConnect == TRUE)
|
{
|
Disconnect();
|
}
|
|
return FALSE;
|
}
|
}
|
else
|
{
|
//NotifyMessageToParent(eFTPConnectionFail,m_strIP,m_strDefaultFolderPath, TRUE);
|
}
|
|
return TRUE;
|
}
|
|
|
BOOL CFTPThreadPool::Connect()
|
{
|
if(m_bSharedFolder)
|
{
|
return TRUE;
|
}
|
Disconnect();
|
|
if(m_pSession == NULL)
|
{
|
m_pSession = new CInternetSession();
|
}
|
|
m_pSession->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,m_nConnectionTimeout);
|
m_pSession->SetOption(INTERNET_OPTION_SEND_TIMEOUT,m_nConnectionTimeout); // GetLastError �ÿ� ERROR_INTERNET_TIMEOUT ������ �����Ѵ�.
|
|
try
|
{
|
TRACE(_T("FTP Connection Try ! \n"));
|
m_pConnection = m_pSession->GetFtpConnection(m_strIP,m_strID,m_strPassword,m_nPort,m_bPassive);
|
//NotifyMessageToParent(eFTPConnection,m_strIP,m_strDefaultFolderPath);
|
TRACE(_T("FTP Connection OK ! \n"));
|
}
|
catch (CInternetException* pEx)
|
{
|
TCHAR szCause[255]={0};
|
if (pEx->GetErrorMessage(szCause, 255))
|
{
|
TRACE(_T("FTP Connection Fail Cause[%s]\n"), szCause);
|
|
m_strLastErrorMessage = szCause;
|
}
|
pEx->Delete();
|
|
if (m_pConnection)
|
delete m_pConnection;
|
m_pConnection = NULL;
|
|
m_pSession->Close();
|
if (m_pSession)
|
delete m_pSession;
|
m_pSession = NULL;
|
|
return 0;
|
}
|
|
if(m_pConnection == NULL)
|
{
|
m_pSession->Close();
|
if (m_pSession)
|
delete m_pSession;
|
m_pSession = NULL;
|
|
m_pConnection = NULL;
|
|
return FALSE;
|
}
|
|
CString strCurrentPath = _T("");
|
m_pConnection->GetCurrentDirectory(strCurrentPath);
|
TRACE("FTP Connection Success Dir[%s] \n",strCurrentPath);
|
|
if (m_pFileFind==NULL)
|
{
|
m_pFileFind = new CFtpFileFind(m_pConnection);
|
}
|
|
return TRUE;
|
}
|
|
BOOL CFTPThreadPool::Disconnect()
|
{
|
if (m_pConnection != NULL)
|
{
|
m_pConnection->Close();
|
delete m_pConnection;
|
m_pConnection = NULL;
|
}
|
|
if(m_pSession != NULL)
|
{
|
m_pSession->Close();
|
delete m_pSession;
|
m_pSession = NULL;
|
}
|
|
if(m_pFileFind != NULL)
|
{
|
m_pFileFind->Close();
|
delete m_pFileFind;
|
m_pFileFind = NULL;
|
}
|
|
m_bConnect = FALSE;
|
|
return TRUE;
|
}
|
|
BOOL CFTPThreadPool::ChangeDirectory( const CString& strPath, BOOL bCreate )
|
{
|
if(m_bSharedFolder) return TRUE;
|
|
if(m_pConnection == NULL)
|
return FALSE;
|
|
BOOL bReturn = m_pConnection->SetCurrentDirectory(strPath);
|
|
if (bCreate==FALSE)
|
{
|
return bReturn;
|
}
|
|
// ������ ������ �̵��� ���� �Ѵٸ� For�� ���鼭 ������ �����Ѵ�.
|
CString strFinalPath = strPath;
|
int nStartIdx = 1;
|
while(TRUE)
|
{
|
int nFindIdx = strFinalPath.Find(_T("/"),nStartIdx);
|
if(nFindIdx == -1)
|
break;
|
|
CString strSubPath = strFinalPath.Left(nFindIdx);
|
if(m_pConnection->SetCurrentDirectory(strSubPath) == FALSE)
|
{
|
if(m_pConnection->CreateDirectory(strSubPath) == FALSE)
|
{
|
return FALSE;
|
}
|
else
|
{
|
nStartIdx = nFindIdx + 1;
|
}
|
}
|
else
|
{
|
nStartIdx = nFindIdx + 1;
|
}
|
Sleep(10);
|
}
|
|
return TRUE;
|
}
|
|
BOOL CFTPThreadPool::Upload_Signal( const CFTPUploadParam& Param )
|
{
|
CString strMessage = _T("");
|
BOOL bUploadResult = FALSE;
|
|
// ���� ���� ��� �����
|
CString strServer_FinalPath = m_strDefaultFolderPath + Param.m_strServer_SignalFolderName;
|
strServer_FinalPath += _T("/");
|
|
// ���� ��� ���� ������ ���� ����
|
if(m_bSharedFolder)
|
{
|
CString strCreatePath;
|
strCreatePath = "\\\\"+m_strIP+strServer_FinalPath;
|
CreatePathDir(strCreatePath);
|
}
|
else
|
{
|
ChangeDirectory(strServer_FinalPath, TRUE);
|
}
|
|
// ���� �ñ׳� ���� ���
|
CString strLocalSignalPath = LOCAL_SIGNAL_FILE_PATH;
|
strLocalSignalPath += _T("\\");
|
strLocalSignalPath += Param.m_strServer_SignalFileName;
|
|
// ���ÿ� �ñ׳� ���� �����
|
CFile SignalFile;
|
if (SignalFile.Open((LPCTSTR)strLocalSignalPath, CFile::modeCreate))
|
{
|
SignalFile.Close();
|
|
// ����Ʈ ��ũ�� ���� ���
|
strServer_FinalPath = strServer_FinalPath + Param.m_strServer_SignalFileName;
|
|
// �ñ׳� ���� ���ε�
|
if(m_bSharedFolder)
|
{
|
bUploadResult = CopyFile(strLocalSignalPath, strServer_FinalPath, FALSE);
|
}
|
else
|
{
|
bUploadResult = m_pConnection->PutFile(strLocalSignalPath, strServer_FinalPath);
|
}
|
|
// ���� �ñ׳� ���� ����
|
DeleteFile(strLocalSignalPath);
|
|
// ��� �α� ���
|
DisplayResultMessage(bUploadResult, strServer_FinalPath, strLocalSignalPath);
|
|
}
|
|
return bUploadResult;
|
}
|
|
BOOL CFTPThreadPool::Upload( const CFTPUploadParam& Param )
|
{
|
if(m_bSharedFolder == FALSE && m_pConnection == NULL)
|
{
|
return FALSE;
|
}
|
|
CString strMessage = _T("");
|
BOOL bUploadResult = TRUE;
|
CString strConfigBackUpIp = _T("12.96.66.96"); // RTMS PC IP [ 21-03-03 KJG ] // RTMS PC ID/PW : administrator / dit1234!@
|
CString strConfigBackUpPath =_T("DIT_AutoConfigBackUp\\"); // RTMS PC�� Config ���� ���ε� ��� [ 21-03-03 KJG ]
|
// [C-PRJ] Image Upload Define - KHT (2020/11/19)
|
// ���� ���� ��� �����
|
CString strServer_FinalPath, strServer_WSIFinalPath = _T("");
|
|
if(Param.m_nDataType == FTPDataType_Image)
|
{
|
strServer_FinalPath = m_strDefaultFolderPath2 + Param.m_strServer_FolderName;
|
|
if(m_bWSIChk)
|
{
|
strServer_WSIFinalPath = m_strDefaultFolderPath2 + Param.m_strServer_FolderName + _T("\WSI\\");
|
}
|
}
|
else
|
{
|
strServer_FinalPath = m_strDefaultFolderPath + Param.m_strServer_FolderName;
|
}
|
if(Param.m_nDataType == FTPDataType_AutoBackUp) // RTMS PC�� Config ���� ���ε� ��� [ 21-03-03 KJG ]
|
{
|
strServer_FinalPath.Format("%s%s", strConfigBackUpPath, Param.m_strServer_FolderName);
|
}
|
|
//strServer_FinalPath += _T("\\");
|
|
// ���� ��� ���� ������ ���� ����
|
if(m_bSharedFolder)
|
{
|
CString strCreatePath;
|
CString strWSICreatePath =_T("");
|
|
// [C-PRJ] Image Upload Define - KHT (2020/11/19)
|
if(Param.m_nDataType == FTPDataType_Image)
|
{
|
strCreatePath = "\\\\" + m_strIP2+ "\\" + strServer_FinalPath;
|
|
if(m_bWSIChk)
|
{
|
strWSICreatePath = "\\\\" + m_strIP2+ "\\" + strServer_FinalPath + _T("\WSI\\");
|
CreatePathDir(strWSICreatePath);
|
}
|
}
|
else
|
{
|
strCreatePath = "\\\\"+m_strIP+ "\\" + strServer_FinalPath;
|
}
|
if(Param.m_nDataType == FTPDataType_AutoBackUp) // RTMS PC�� Config ���� ���ε� ��� [ 21-03-03 KJG ]
|
{
|
strCreatePath.Format("\\\\%s\\%s", strConfigBackUpIp, strServer_FinalPath);
|
}
|
|
CreatePathDir(strCreatePath);
|
}
|
else
|
{
|
ChangeDirectory(strServer_FinalPath, TRUE);
|
}
|
|
|
//Raw ���� ��� �߰�
|
CString strServerSubRawFileFullPathName=NULL;
|
if(Param.m_nDataType == FTPDataType_Raw)
|
{
|
CreatePathDir(Param.m_strServer_SubFilePath);
|
strServerSubRawFileFullPathName = Param.m_strServer_SubFilePath;
|
strServerSubRawFileFullPathName += Param.m_strServer_SubFileName;
|
}
|
|
|
|
// ���� Ǯ ��θ� �����
|
CString strLocal_FullPathName = Param.m_strLocal_FolderName;
|
strLocal_FullPathName += _T("\\");
|
strLocal_FullPathName += Param.m_strLocal_FileName;
|
|
// ���� ��ο��� �ø� ���� ã��
|
CFileFind finder;
|
CString strServer_FullPathName =_T("");
|
BOOL bFind = finder.FindFile(strLocal_FullPathName);
|
while(bFind)
|
{
|
Sleep(10);
|
bFind = finder.FindNextFile();
|
|
if (finder.IsDots()) continue;
|
if (finder.IsDirectory()) continue;
|
|
// ���� Ǯ ��θ� �����
|
strServer_FullPathName = strServer_FinalPath + finder.GetFileName();
|
|
// ���� Ǯ ��θ� �����
|
strLocal_FullPathName = finder.GetFilePath();
|
|
// ���ε�
|
if(m_bSharedFolder)
|
{
|
// [C-PRJ] Image Upload Define - KHT (2020/11/19)
|
if(Param.m_nDataType == FTPDataType_Image)
|
{
|
strServer_FullPathName = "\\\\"+m_strIP2+ "\\" + strServer_FinalPath + finder.GetFileName();
|
}
|
else
|
{
|
strServer_FullPathName = "\\\\"+m_strIP+ "\\" + strServer_FinalPath + finder.GetFileName();
|
}
|
if(Param.m_nDataType == FTPDataType_AutoBackUp) // RTMS PC�� Config ���� ���ε� ��� [ 21-03-03 KJG ]
|
{
|
strServer_FullPathName = "\\\\"+ strConfigBackUpIp + "\\" + strServer_FinalPath + finder.GetFileName();
|
}
|
strServer_FullPathName.MakeLower();
|
strServer_FullPathName.Replace("/", "\\");
|
//LYW
|
// ���� ��ο� �ش� Raw������ �ִٸ� �ð��� �ٿ��� ���(Rename) [ 21-04-16 KJG ]
|
if(Param.m_nDataType ==FTPDataType_Raw && m_bBDIStackDown)
|
{
|
CFileFind cfinder;
|
BOOL bFileExist = cfinder.FindFile(strServer_FullPathName);
|
if(bFileExist)
|
{
|
CString strCreationTime;
|
CTime tmFileCreation;
|
|
cfinder.FindNextFile();
|
cfinder.GetLastWriteTime(tmFileCreation);
|
strCreationTime.Format(_T("_%04d%02d%02d%02d%02d%02d"),
|
tmFileCreation.GetYear(), tmFileCreation.GetMonth(), tmFileCreation.GetDay(), tmFileCreation.GetHour(), tmFileCreation.GetMinute(), tmFileCreation.GetSecond());
|
CFile::Rename(strServer_FullPathName, strServer_FullPathName + strCreationTime);
|
DisplayResultMessage(bUploadResult, "Exist RawFile Change RawFile Name %s",strServer_FullPathName + strCreationTime);
|
Sleep(30); // Rename ���ð�
|
}
|
}
|
//LYW
|
bUploadResult = CopyFile(strLocal_FullPathName, strServer_FullPathName, FALSE);
|
CopyFile(strLocal_FullPathName,strServerSubRawFileFullPathName, FALSE);
|
}
|
else
|
{
|
bUploadResult = m_pConnection->PutFile(strLocal_FullPathName, strServer_FullPathName);
|
}
|
|
if(bUploadResult == FALSE)
|
{
|
DWORD dwResut = GetLastError();
|
int a = 0;
|
}
|
|
// ��� �α� ���
|
DisplayResultMessage(bUploadResult, strServer_FullPathName, strLocal_FullPathName);
|
}
|
finder.Close();
|
|
if(Param.m_nDataType == FTPDataType_Image && m_bWSIChk)
|
{
|
// WSI ���� Ǯ ��θ� �����
|
CString strWSILocal_FullPathName = Param.m_strLocal_FolderName;
|
strWSILocal_FullPathName += _T("\\WSI\\");
|
strWSILocal_FullPathName += Param.m_strLocal_FileName;
|
|
// WSI ���� ��ο��� �ø� ���� ã��
|
CFileFind finder;
|
CString strServer_WSIFullPathName =_T("");
|
BOOL bFind = finder.FindFile(strWSILocal_FullPathName);
|
while(bFind)
|
{
|
Sleep(10);
|
bFind = finder.FindNextFile();
|
|
if (finder.IsDots()) continue;
|
if (finder.IsDirectory()) continue;
|
|
// ���� Ǯ ��θ� �����
|
strServer_WSIFullPathName = strServer_WSIFinalPath + finder.GetFileName();
|
|
// ���� Ǯ ��θ� �����
|
strWSILocal_FullPathName = finder.GetFilePath();
|
|
// ���ε�
|
if(m_bSharedFolder)
|
{
|
strServer_WSIFullPathName = "\\\\"+m_strIP2+ "\\" + strServer_WSIFinalPath + finder.GetFileName();
|
|
strServer_WSIFullPathName.MakeLower();
|
strServer_WSIFullPathName.Replace("/", "\\");
|
|
bUploadResult = CopyFile(strWSILocal_FullPathName, strServer_WSIFullPathName, FALSE);
|
}
|
else
|
{
|
bUploadResult = m_pConnection->PutFile(strWSILocal_FullPathName, strServer_WSIFullPathName);
|
}
|
|
if(bUploadResult == FALSE)
|
{
|
DWORD dwResut = GetLastError();
|
int a = 0;
|
}
|
|
// ��� �α� ���
|
DisplayResultMessage(bUploadResult, strServer_WSIFullPathName, strWSILocal_FullPathName);
|
}
|
finder.Close();
|
}
|
|
if(Param.m_nDataType == FTPDataType_Image)
|
{
|
CString RTMSFile =NULL;
|
CString RTMSName = NULL;
|
CTime time;
|
BOOL bCopy;
|
time = CTime::GetCurrentTime();
|
|
RTMSFile = Param.m_strRTMS_FileName;
|
RTMSName = RTMSFile.Right( RTMSFile.GetLength() - RTMSFile.ReverseFind('\\')-1);;
|
|
RTMSName = RTMSName.Left(RTMSName.GetLength() - 21);
|
RTMSFile = "D:\\RTMS_Signal\\" + RTMSName;
|
|
RTMSFile.Format(RTMSFile + "%04d%02d%02d%02d%02d%02d.Signal",time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
|
|
//���� �̵�
|
bUploadResult = ::CopyFile(Param.m_strRTMS_FileName, RTMSFile,FALSE);
|
|
DisplayResultMessage(bUploadResult,Param.m_strRTMS_FileName,RTMSFile);
|
|
}
|
|
// �ñ׳� ������ ���ε��ؾ��ϸ�.
|
if( Param.m_nCreateSignalFile == 1)
|
{
|
Upload_Signal(Param);
|
}
|
|
return bUploadResult;
|
}
|
|
BOOL CFTPThreadPool::Download( const CFTPUploadParam& Param)
|
{
|
if(m_bSharedFolder == FALSE && m_pConnection == NULL)
|
return FALSE;
|
|
// ���� ���� ���
|
CString strServer_FinalPath = m_strDefaultFolderPath3 + Param.m_strServer_FolderName + "/";
|
|
//201208 CJH - Stack �� �߰�
|
if(m_bSharedFolder)
|
{
|
CString strCreatePath;
|
strCreatePath = "\\\\"+m_strIP3+ "\\" + strServer_FinalPath;
|
//CreatePathDir(strCreatePath);
|
}
|
else
|
{
|
ChangeDirectory(strServer_FinalPath, TRUE);
|
}
|
|
// ���� ���� ���
|
BOOL bDownResult = TRUE;
|
CString strLocal_FullPathName = Param.m_strLocal_FolderName;
|
strLocal_FullPathName += _T("\\");
|
|
try
|
{
|
// ���� ���� ����
|
if(m_bSharedFolder)
|
{
|
strServer_FinalPath = "\\\\"+m_strIP3+ m_strDefaultFolderPath3 + Param.m_strServer_FolderName + "/" ;
|
strServer_FinalPath.Replace("/", "\\");
|
}
|
else
|
{
|
strServer_FinalPath += Param.m_strServer_FileName;
|
}
|
|
if(m_bSharedFolder)
|
{
|
CFileFind finder;
|
|
// start looping
|
CString strLocal_FullFileName = _T("");
|
CString strServer_FindFormat = strServer_FinalPath + Param.m_strServer_FileName;
|
BOOL bWorking = finder.FindFile(strServer_FindFormat);
|
while (bWorking)
|
{
|
bWorking = finder.FindNextFile();
|
if (finder.IsDirectory()) continue;
|
if (finder.IsDots()) continue;
|
|
|
CString strValue = finder.GetFileName();
|
|
// ���� Ǯ ��� �����
|
strLocal_FullFileName = strLocal_FullPathName + Param.m_strLocal_FileName;
|
|
CString strServerFileName = strServer_FinalPath + finder.GetFileName();
|
// �ٿ�ε�
|
bDownResult = bDownResult & CopyFile(strServerFileName, strLocal_FullFileName, FALSE);
|
|
// ��� �α� ���
|
DisplayResultMessage(bDownResult, strServerFileName, strLocal_FullFileName);
|
|
}
|
finder.Close();
|
}
|
else
|
{
|
CFtpFileFind finder(m_pConnection);
|
|
// start looping
|
CString strLocal_FullFileName = _T("");
|
BOOL bWorking = finder.FindFile(strServer_FinalPath);
|
while (bWorking)
|
{
|
bWorking = finder.FindNextFile();
|
if (finder.IsDirectory()) continue;
|
if (finder.IsDots()) continue;
|
|
|
CString strValue = finder.GetFileName();
|
|
// ���� Ǯ ��� �����
|
strLocal_FullFileName = strLocal_FullPathName + Param.m_strServer_FileName;//finder.GetFileName();
|
|
// ���� Ǯ ��� ��������
|
strServer_FinalPath = strServer_FinalPath;//finder.GetFilePath();
|
|
// �ٿ�ε�
|
bDownResult = bDownResult & m_pConnection->GetFile(strServer_FinalPath, strLocal_FullFileName, FALSE);
|
|
// ��� �α� ���
|
DisplayResultMessage(bDownResult, strServer_FinalPath, strLocal_FullFileName);
|
}
|
finder.Close();
|
}
|
|
}
|
catch (CInternetException* pEx)
|
{
|
TCHAR sz[1024];
|
pEx->GetErrorMessage(sz, 1024);
|
_tprintf_s(_T("ERROR! %s\n"), sz);
|
pEx->Delete();
|
}
|
|
return bDownResult;
|
}
|
|
|
CString CFTPThreadPool::GetInternetErrorCodeToString( DWORD dwErrorCode )
|
{
|
CString strRet = _T("Invalid");
|
|
if( m_strLastErrorMessage != _T(""))
|
{
|
strRet = m_strLastErrorMessage;
|
m_strLastErrorMessage = _T("");
|
return strRet;
|
}
|
|
switch(dwErrorCode)
|
{
|
case ERROR_INTERNET_OUT_OF_HANDLES : strRet = _T("ERROR_INTERNET_OUT_OF_HANDLES �Ҵ��� �� �ִ� ���ͳ� �ڵ��� �����ϴ�. "); break;
|
case ERROR_INTERNET_TIMEOUT : strRet = _T("ERROR_INTERNET_TIMEOUT �۾� �ð��� �ʰ��߽��ϴ�. "); break;
|
case ERROR_INTERNET_EXTENDED_ERROR : strRet = _T("ERROR_INTERNET_EXTENDED_ERROR �������� Ȯ�� ������ ��ȯ�߽��ϴ�. "); break;
|
case ERROR_INTERNET_INTERNAL_ERROR : strRet = _T("ERROR_INTERNET_INTERNAL_ERROR Microsoft ���ͳ� Ȯ�忡�� ���� ������ ���߽��ϴ�. "); break;
|
case ERROR_INTERNET_INVALID_URL : strRet = _T("ERROR_INTERNET_INVALID_URL �߸��� URL�Դϴ�. "); break;
|
case ERROR_INTERNET_UNRECOGNIZED_SCHEME : strRet = _T("ERROR_INTERNET_UNRECOGNIZED_SCHEME URL���� �νĵ� ���������� ������� �ʽ��ϴ�. "); break;
|
case ERROR_INTERNET_NAME_NOT_RESOLVED : strRet = _T("ERROR_INTERNET_NAME_NOT_RESOLVED ���� �̸��̳� �ּҸ� Ȯ���� �� �����ϴ�. "); break;
|
case ERROR_INTERNET_PROTOCOL_NOT_FOUND : strRet = _T("ERROR_INTERNET_PROTOCOL_NOT_FOUND �ʿ��� ����� ���Ե� ���������� ã�� �� �����ϴ�. "); break;
|
case ERROR_INTERNET_INVALID_OPTION : strRet = _T("ERROR_INTERNET_INVALID_OPTION �߸��� �ɼ��Դϴ�. "); break;
|
case ERROR_INTERNET_BAD_OPTION_LENGTH : strRet = _T("ERROR_INTERNET_BAD_OPTION_LENGTH �ɼ� ������ ���� ���̰� ���� �ʽ��ϴ�. "); break;
|
case ERROR_INTERNET_OPTION_NOT_SETTABLE : strRet = _T("ERROR_INTERNET_OPTION_NOT_SETTABLE �ɼ� ���� ������ �� �����ϴ�. "); break;
|
case ERROR_INTERNET_SHUTDOWN : strRet = _T("ERROR_INTERNET_SHUTDOWN Microsoft ���ͳ� Ȯ�� ������ ����Ǿ����ϴ�. "); break;
|
case ERROR_INTERNET_INCORRECT_USER_NAME : strRet = _T("ERROR_INTERNET_INCORRECT_USER_NAME ����� �� ���� ����� �̸��Դϴ�. "); break;
|
case ERROR_INTERNET_INCORRECT_PASSWORD : strRet = _T("ERROR_INTERNET_INCORRECT_PASSWORD ����� �� ���� ��ȣ�Դϴ�. "); break;
|
case ERROR_INTERNET_LOGIN_FAILURE : strRet = _T("ERROR_INTERNET_LOGIN_FAILURE �α��� ��û�� �źεǾ����ϴ�. "); break;
|
case ERROR_INTERNET_INVALID_OPERATION : strRet = _T("ERROR_INTERNET_INVALID_OPERATION "); break;
|
case ERROR_INTERNET_OPERATION_CANCELLED : strRet = _T("ERROR_INTERNET_OPERATION_CANCELLED �۾��� ��ҵǾ����ϴ�. "); break;
|
case ERROR_INTERNET_INCORRECT_HANDLE_TYPE : strRet = _T("ERROR_INTERNET_INCORRECT_HANDLE_TYPE ������ �ڵ��� ��û�� �۾��� ����� �� ���� �����Դϴ�. "); break;
|
case ERROR_INTERNET_INCORRECT_HANDLE_STATE : strRet = _T("ERROR_INTERNET_INCORRECT_HANDLE_STATE ��û�� �۾��� ����� �� ���� ������ �ڵ��Դϴ�. "); break;
|
case ERROR_INTERNET_NOT_PROXY_REQUEST : strRet = _T("ERROR_INTERNET_NOT_PROXY_REQUEST ���Ͻ� ���ǿ��� ��û�� �� �����ϴ�. "); break;
|
case ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND : strRet = _T("ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND ������Ʈ�� ���� ã�� �� �����ϴ�. "); break;
|
case ERROR_INTERNET_BAD_REGISTRY_PARAMETER : strRet = _T("ERROR_INTERNET_BAD_REGISTRY_PARAMETER ������Ʈ�� �Ű� ������ ���� �ʽ��ϴ�. "); break;
|
case ERROR_INTERNET_NO_DIRECT_ACCESS : strRet = _T("ERROR_INTERNET_NO_DIRECT_ACCESS ���� ���ͳݿ� ������ �� �����ϴ�. "); break;
|
case ERROR_INTERNET_NO_CONTEXT : strRet = _T("ERROR_INTERNET_NO_CONTEXT ���ؽ�Ʈ ���� �������� �ʾҽ��ϴ�. "); break;
|
case ERROR_INTERNET_NO_CALLBACK : strRet = _T("ERROR_INTERNET_NO_CALLBACK ���� �ݹ��� �������� �ʾҽ��ϴ�. "); break;
|
case ERROR_INTERNET_REQUEST_PENDING : strRet = _T("ERROR_INTERNET_REQUEST_PENDING ���� �ذ���� ���� ��û�� �ֽ��ϴ�. "); break;
|
case ERROR_INTERNET_INCORRECT_FORMAT : strRet = _T("ERROR_INTERNET_INCORRECT_FORMAT ���� ������ ���� �ʽ��ϴ�. "); break;
|
case ERROR_INTERNET_ITEM_NOT_FOUND : strRet = _T("ERROR_INTERNET_ITEM_NOT_FOUND ��û�� ���� ã�� �� �����ϴ�. "); break;
|
case ERROR_INTERNET_CANNOT_CONNECT : strRet = _T("ERROR_INTERNET_CANNOT_CONNECT ������ ������ �� �����ϴ�. "); break;
|
case ERROR_INTERNET_CONNECTION_ABORTED : strRet = _T("ERROR_INTERNET_CONNECTION_ABORTED �������� ������ ������������ ����Ǿ����ϴ�. "); break;
|
case ERROR_INTERNET_CONNECTION_RESET : strRet = _T("ERROR_INTERNET_CONNECTION_RESET �������� ������ �ٽ� �����߽��ϴ�. "); break;
|
case ERROR_INTERNET_FORCE_RETRY : strRet = _T("ERROR_INTERNET_FORCE_RETRY �۾��� �ٽ� �õ��ؾ� �մϴ�. "); break;
|
case ERROR_INTERNET_INVALID_PROXY_REQUEST : strRet = _T("ERROR_INTERNET_INVALID_PROXY_REQUEST �߸��� ���Ͻ� ��û�Դϴ�. "); break;
|
case ERROR_INTERNET_NEED_UI : strRet = _T("ERROR_INTERNET_NEED_UI �۾��� �Ϸ��Ϸ��� ������� ������ �ʿ��մϴ�. "); break;
|
case ERROR_INTERNET_HANDLE_EXISTS : strRet = _T("ERROR_INTERNET_HANDLE_EXISTS �ڵ��� �̹� �ֽ��ϴ�. "); break;
|
case ERROR_INTERNET_SEC_CERT_DATE_INVALID : strRet = _T("ERROR_INTERNET_SEC_CERT_DATE_INVALID ������ ��¥�� �߸��Ǿ��ų� ����Ǿ����ϴ�. "); break;
|
case ERROR_INTERNET_SEC_CERT_CN_INVALID : strRet = _T("ERROR_INTERNET_SEC_CERT_CN_INVALID ������ ȣ��Ʈ �̸��� �߸��Ǿ��ų� ��ġ���� �ʽ��ϴ�. "); break;
|
case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR : strRet = _T("ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR ���� ��û���� �� ������ ���� ����� �����մϴ�. "); break;
|
case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR : strRet = _T("ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR ���� ��û���� ���� ������ �� ����� �����մϴ�. "); break;
|
case ERROR_INTERNET_MIXED_SECURITY : strRet = _T("ERROR_INTERNET_MIXED_SECURITY ���� �� �� ������ ȥ�յǾ� �ֽ��ϴ�. "); break;
|
case ERROR_INTERNET_CHG_POST_IS_NON_SECURE : strRet = _T("ERROR_INTERNET_CHG_POST_IS_NON_SECURE �� �Խ÷� �����ϰ� �ֽ��ϴ�. "); break;
|
case ERROR_INTERNET_POST_IS_NON_SECURE : strRet = _T("ERROR_INTERNET_POST_IS_NON_SECURE �� ���� ���¿��� ������ �Խ��ϰ� �ֽ��ϴ�. "); break;
|
case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED : strRet = _T("ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED Ŭ���̾�Ʈ ������ �Ϸ��Ϸ��� �������� �ʿ��մϴ�. "); break;
|
case ERROR_INTERNET_INVALID_CA : strRet = _T("ERROR_INTERNET_INVALID_CA ���� ����� �߸��Ǿ��ų� ���� �ʽ��ϴ�. "); break;
|
case ERROR_INTERNET_CLIENT_AUTH_NOT_SETUP : strRet = _T("ERROR_INTERNET_CLIENT_AUTH_NOT_SETUP Ŭ���̾�Ʈ ������ �ùٸ��� ��ġ���� �ʾҽ��ϴ�. "); break;
|
case ERROR_INTERNET_ASYNC_THREAD_FAILED : strRet = _T("ERROR_INTERNET_ASYNC_THREAD_FAILED Wininet �� �����忡�� ������ ���߽��ϴ�.�ٽ� �����ؾ� �մϴ�. "); break;
|
case ERROR_INTERNET_REDIRECT_SCHEME_CHANGE : strRet = _T("ERROR_INTERNET_REDIRECT_SCHEME_CHANGE ���� �۾� �� �������� ��Ű���� ����Ǿ����ϴ�. "); break;
|
case ERROR_INTERNET_DIALOG_PENDING : strRet = _T("ERROR_INTERNET_DIALOG_PENDING �ٽ� �õ��� ������ ��� ���� �۾��� �ֽ��ϴ�. "); break;
|
case ERROR_INTERNET_RETRY_DIALOG : strRet = _T("ERROR_INTERNET_RETRY_DIALOG �۾��� �ٽ� �õ��ؾ� �մϴ�. "); break;
|
case ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR : strRet = _T("ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR ���� ���� ���˿� ���� �� �۾��� �ٽ� �õ��ؾ� �մϴ�. "); break;
|
case ERROR_INTERNET_INSERT_CDROM : strRet = _T("ERROR_INTERNET_INSERT_CDROM "); break;
|
case ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED : strRet = _T("ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED "); break;
|
case ERROR_INTERNET_SEC_CERT_ERRORS : strRet = _T("ERROR_INTERNET_SEC_CERT_ERRORS "); break;
|
case ERROR_INTERNET_SEC_CERT_NO_REV : strRet = _T("ERROR_INTERNET_SEC_CERT_NO_REV "); break;
|
case ERROR_INTERNET_SEC_CERT_REV_FAILED : strRet = _T("ERROR_INTERNET_SEC_CERT_REV_FAILED "); break;
|
}
|
|
|
return strRet;
|
}
|
|
void CFTPThreadPool::DisplayLogMessage( const CString& strMessage )
|
{
|
if (m_pIFTP2P==NULL) return;
|
|
CSingleLock localLock(&m_csLogIndex);
|
localLock.Lock();
|
|
m_strLogBuffer[m_nCurLogIndex] = strMessage;
|
m_pIFTP2P->IFTP2P_DisplayLogMessage(m_nType, m_nCurLogIndex);
|
|
m_nCurLogIndex = (++m_nCurLogIndex) % MAX_BUFFER_COUNT;
|
}
|
|
void CFTPThreadPool::DisplayResultMessage( BOOL bResult, const CString& strServer, const CString& strLocal )
|
{
|
CString strTemp = _T("");
|
if (bResult)
|
{
|
strTemp = _T("Success! ");
|
}
|
else
|
{
|
strTemp = _T("FAIL! ");
|
}
|
|
CString strMesssage = strTemp+ _T("[Server] ") + strServer;
|
DisplayLogMessage(strMesssage);
|
|
strMesssage = strTemp+ _T("[Local] ") + strLocal;
|
DisplayLogMessage(strMesssage);
|
}
|
|
void CFTPThreadPool::DisplaynNotifyTypeMessage( int nNotifyType, const CString& strMessage )
|
{
|
if (m_pIFTP2P==NULL) return;
|
|
CSingleLock localLock(&m_csLogIndex);
|
localLock.Lock();
|
|
m_strLogBuffer[m_nCurLogIndex] = strMessage;
|
m_pIFTP2P->IFTP2P_DisplayNotifyMessage(m_nType, nNotifyType, m_nCurLogIndex);
|
|
m_nCurLogIndex = (++m_nCurLogIndex) % MAX_BUFFER_COUNT;
|
}
|
|
|
const CString* CFTPThreadPool::GetLogBuffer( int nIndex )
|
{
|
if (nIndex<0 || nIndex>=MAX_BUFFER_COUNT) return NULL;
|
return &m_strLogBuffer[nIndex];
|
}
|
|
const CFTPUploadParam* CFTPThreadPool::GetUploadList( int nIdx )
|
{
|
if (nIdx<0 || nIdx>=(int)m_deqUploadList.size()) return NULL;
|
|
return &(m_deqUploadList.at(nIdx));
|
}
|
|
void CFTPThreadPool::GetUploadList( DeqFTPUploadParam& deqUploadParam )
|
{
|
CSingleLock localLock(&m_csUploadList);
|
localLock.Lock();
|
|
deqUploadParam = m_deqUploadList;
|
}
|
|
void CFTPThreadPool::GetUploadListCountInfo( UINT& nReadyCount, UINT& nProcessCount, UINT& nCompletCount, UINT& nTotalCount )
|
{
|
nReadyCount = (UINT)m_deqUploadList.size();
|
nProcessCount = m_nProcessCount;
|
nCompletCount = m_nCompletCount;
|
nTotalCount = m_nTotalCount;
|
}
|
|
void CFTPThreadPool::NotifyMessage( int nNotifyType, const CString& strUploadPath, const CString& strLocalPath, BOOL bSendErrorCode )
|
{
|
CString strBuffer = _T("");
|
|
switch(nNotifyType)
|
{
|
case eFTPConnection:
|
{
|
strBuffer.Format(_T("FTP Connection - IP[%s] Home[%s]"), strUploadPath, strLocalPath);
|
}
|
break;
|
case eFTPDisConnection:
|
{
|
strBuffer.Format(_T("FTP DisConnection - IP[%s] Home[%s]"), strUploadPath, strLocalPath);
|
}
|
break;
|
case eFTPConnectionFail:
|
{
|
strBuffer.Format(_T("FTP Connection Fail - IP[%s] Home[%s] Error Code[%d - %s] "), strUploadPath, strLocalPath, GetLastError(), GetInternetErrorCodeToString( GetLastError() ) );
|
}
|
break;
|
case eFTPFileUploadSuccess:
|
{
|
strBuffer.Format(_T("!!!FTP Upload Success"));
|
}
|
break;
|
case eFTPFileUploadFail:
|
{
|
strBuffer.Format(_T("FTP Upload Fail Error Code[%d - %s] "), GetLastError(), GetInternetErrorCodeToString( GetLastError() ) );
|
}
|
break;
|
case eFTPFileDownloadSuccess:
|
{
|
strBuffer.Format(_T("!!!FTP Download Success"));
|
}
|
break;
|
case eFTPFileDownloadFail:
|
{
|
strBuffer.Format(_T("FTP Download Fail - Error Code[%d - %s] "), GetLastError(), GetInternetErrorCodeToString( GetLastError() ) );
|
}
|
break;
|
case eFTPError:
|
{
|
strBuffer.Format(_T("FTP Error - [%s] [%s] Error Code[%d - %s] "), strUploadPath, strLocalPath, GetLastError(), GetInternetErrorCodeToString( GetLastError() ) );
|
}
|
break;
|
|
}
|
|
DisplaynNotifyTypeMessage(nNotifyType, strBuffer);
|
}
|