DWORD WINAPI sendFileThread(LPVOID lpParam) { char *filename = (char *)lpParam; try { char installPath[1024]; CModuleUtil::getInstallPath(installPath); char fname[1024]; sprintf(fname, "%s\\%s", installPath, filename); char fnameGz[1024]; sprintf(fnameGz, "%s\\%s.gz", installPath, filename); char remoteFileName[128]; sprintf(remoteFileName, "incoming/%s-%d-%d.gz", filename, time(NULL), rand()); file_compress(fname, "wb"); CInternetSession session; CFtpConnection *ftpConnection = session.GetFtpConnection("upload.tibiaauto.net", "anonymous", "*****@*****.**", 21, true); ftpConnection->PutFile(fnameGz, remoteFileName); ftpConnection->Close(); delete ftpConnection; _unlink(fname); _unlink(fnameGz); fileSendingProgress = 1; } catch (CInternetException*) { fileSendingProgress = -1; } return 0; }
BOOL CFtpFileDlg::PutFile( CString strSourceName,CString strDesName ) { CInternetSession* pSession; CFtpConnection *pConnection; pConnection = NULL; pSession = new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS); try{ pConnection = pSession->GetFtpConnection(m_strFtpSite,m_strName,m_strPwd); } catch(CInternetException *e){ e->Delete(); pConnection = NULL; return FALSE; } if(pConnection != NULL){ if (!pConnection->PutFile(strSourceName,strDesName)){ pConnection->Close(); delete pConnection; delete pSession; return FALSE; } } if (pConnection != NULL){ pConnection->Close(); delete pConnection; } delete pSession; return TRUE; }
void CFtpFileDlg::ListContent() { CInternetSession* pSession; CFtpConnection* pConnection; CFtpFileFind* pFileFind; CString strFileName; BOOL bContinue; pConnection = NULL; pFileFind = NULL; pSession = new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS); try{ pConnection = pSession->GetFtpConnection(m_strFtpSite,m_strName,m_strPwd); } catch(CInternetException *e){ e->Delete(); pConnection = NULL; AfxMessageBox("连接失败!",MB_OK|MB_ICONSTOP); } if (pConnection!= NULL){ pFileFind = new CFtpFileFind(pConnection); bContinue = pFileFind->FindFile(NULL); if (!bContinue){ pFileFind->Close(); pFileFind=NULL; } while(bContinue){ bContinue = pFileFind->FindNextFile(); strFileName = pFileFind->GetFileName(); if (pFileFind->IsDirectory()) { strFileName = "["+strFileName; strFileName += "]"; } m_ListFile.AddString(strFileName); } if (pFileFind!=NULL){ pFileFind->Close(); pFileFind=NULL; } } delete pFileFind; if (pConnection!=NULL){ pConnection->Close(); delete pConnection; } delete pSession; }
DWORD WINAPI sendMapsThread(LPVOID lpParam) { char *path = (char *)lpParam; try { char fullMask[1024]; sprintf(fullMask, "%s\\*.map", path); WIN32_FIND_DATA data; HANDLE hFind = FindFirstFile(fullMask, &data); if (hFind != INVALID_HANDLE_VALUE) { CInternetSession session; CFtpConnection *ftpConnection = session.GetFtpConnection("upload.tibiaauto.net", "anonymous", "*****@*****.**", 21, true); time_t t = time(NULL); int r = rand(); int lastfile = 1; while (lastfile) { char fname[128]; char fnameGz[128]; sprintf(fname, "%s\\%s", path, data.cFileName); sprintf(fnameGz, "%s\\%s.gz", path, data.cFileName); char remoteFileName[128]; sprintf(remoteFileName, "incoming/%s-%d-%d.gz", data.cFileName, t, r); file_compress(fname, "wb"); ftpConnection->PutFile(fnameGz, remoteFileName); _unlink(fnameGz); lastfile = FindNextFile(hFind, &data); } ftpConnection->Close(); delete ftpConnection; } fileSendingProgress = 1; } catch (CInternetException*) { fileSendingProgress = -1; } // allocated before starting a thread free(path); return 0; }
/** * 数据文件保存到FTP服务器 * @param void * @return bool true:成功;false:失败 */ bool CThreadProcSiteDataOutput::SaveDataFileToFTPServer() { bool bReturn = false; CInternetSession oSession; BOOL bData; CFtpConnection* pConnection = oSession.GetFtpConnection(m_pSiteData->m_strIPFTPServer); bData = SaveDataFileToFTPServer(pConnection, "..\\data\\FileInstrument.dat", "\\data\\FileInstrument.dat"); if(TRUE == bData) { bData = SaveDataFileToFTPServer(pConnection, "..\\data\\FileRout.dat", "\\data\\FileRout.dat"); if(TRUE == bData) { bData = SaveDataFileToFTPServer(pConnection, "..\\data\\FileChannel.dat", "\\data\\FileChannel.dat"); if(TRUE == bData) { bReturn = true; } } } pConnection->Close(); delete pConnection; return bReturn; }
DWORD WINAPI sendPacketLogThread(LPVOID lpParam) { char path[1024]; CModuleUtil::getInstallPath(path); char fullMask[1024]; sprintf(fullMask, "%s\\tascripts\\* statistics.txt", path); WIN32_FIND_DATA data; HANDLE hFind = FindFirstFile(fullMask, &data); if (hFind != INVALID_HANDLE_VALUE) { char fname[128]; int lastfile = 1; while (lastfile) { sprintf(fname, "%s\\tascripts\\%s", path, data.cFileName); FILE* f = fopen(fname, "a+"); if (f) { fseek(f, 0, SEEK_END); int flen = ftell(f); fclose(f); if (flen > 1000) goto sendFiles; } lastfile = FindNextFile(hFind, &data); } } { hFind = FindFirstFile(fullMask, &data); if (hFind != INVALID_HANDLE_VALUE) { char fname[128]; int lastfile = 1; while (lastfile) { sprintf(fname, "%s\\tascripts\\%s", path, data.cFileName); _unlink(fname); lastfile = FindNextFile(hFind, &data); } } fileSendingProgress = 1; return 0; } sendFiles: int msgboxID = -1; if (!CModuleUtil::getTASetting("RemoveBotStatsMessage")) msgboxID = MessageBox(NULL, "TA is about to send your botting statistics to TA.net. You can edit this option in \"General options and statistics\".\n\nWould you like to receive this message every time before TA sends this data?\nUse cancel to stop the operation.", "Submit Botting Data", MB_YESNOCANCEL); if (msgboxID == IDCANCEL) return 0; try { hFind = FindFirstFile(fullMask, &data); if (hFind != INVALID_HANDLE_VALUE) { CInternetSession session; CFtpConnection *ftpConnection = session.GetFtpConnection("upload.tibiaauto.net", "anonymous", "*****@*****.**", 21, true); time_t t = time(NULL); unsigned long serialNumber; GetVolumeInformation(NULL, NULL, 0, &serialNumber, NULL, NULL, NULL, 0); unsigned int r = serialNumber % 0x1000000; int lastfile = 1; while (lastfile) { char fname[128]; char fnameGz[128]; sprintf(fname, "%s\\tascripts\\%s", path, data.cFileName); sprintf(fnameGz, "%s\\tascripts\\%s.gz", path, data.cFileName); char remoteFileName[128]; sprintf(remoteFileName, "incoming/%s-%d-%u.gz", data.cFileName, t, r); file_compress(fname, "wb"); ftpConnection->PutFile(fnameGz, remoteFileName); _unlink(fnameGz); lastfile = FindNextFile(hFind, &data); _unlink(fname); } ftpConnection->Close(); delete ftpConnection; } fileSendingProgress = 1; if (!CModuleUtil::getTASetting("RemoveBotStatsMessage")) AfxMessageBox("Thank you for submitting \"botting statistics.txt\" and \"module statistics.txt\".\n\nNo personally identifiable information was sent.\nThis botting information will be analysed and used to help prevent CIPSoft from automatically detecting TA in the future. You can change this setting in \"General Options and Statistics\".\n\nTA users thank you for helping us towards this end.\n~TA Team"); } catch (CInternetException*) { if (!CModuleUtil::getTASetting("RemoveBotStatsMessage")) AfxMessageBox("Failed to send file. Check your connection to the internet."); fileSendingProgress = -1; } if (msgboxID == IDNO) CModuleUtil::setTASetting("RemoveBotStatsMessage", 1); return 0; }
void CFtpDownloadThread::Run() { USES_CONVERSION; CInternetSession InternetSession; CFtpConnection * pFtpConn = NULL; CInternetFile * pFtpFile = NULL; CString strFtpUrl, fileDir; CFileException fileException; CFile file; UINT nFtpReadSize = 0; BYTE buffer[1024] = {0}; BOOL bIsOpenFile = FALSE; CFtpFileFind * pFtpFind = NULL; strFtpUrl.Format(_T("%s"), A2W(m_strFptURL.c_str())); try { pFtpConn = InternetSession.GetFtpConnection(strFtpUrl, m_strUsr.c_str()?NULL:m_strUsr.c_str(), m_strPwd.c_str()?NULL:m_strPwd.c_str(), m_nftpPort); } catch (CInternetException * pEx) { TCHAR sz[1024]; pEx->GetErrorMessage(sz, 1024); AfxMessageBox(sz); pEx->Delete(); m_nErrorCode = FTP_SERVER_CONNECT_FAILED; goto end; } if (pFtpConn == NULL) { m_nErrorCode = FTP_SERVER_CONNECT_FAILED; goto end; } fileDir.Format(_T("%s\\%s"), m_strSaveDir.c_str(), m_strFileName.c_str()); UINT nMode = 0; //CInternetFile不支持FTP协议的端点续传,需要自己实现。 /*if (PathFileExists(fileDir)) nMode = CFile::modeWrite; else*/ nMode = CFile::modeCreate | CFile::modeReadWrite | CFile::typeBinary; if (!file.Open(fileDir, nMode, &fileException)){ m_nErrorCode = ERR_OPEN_LOACAL_SAVE_FILE; goto end; } bIsOpenFile = TRUE; file.SeekToEnd(); m_nDownloadLen = file.GetLength(); pFtpFind = new CFtpFileFind(pFtpConn); if (!pFtpFind->FindFile(m_strFileName.c_str())) { m_nErrorCode = FTP_SERVER_FILE_OPEN_ERR; pFtpFind->Close(); delete pFtpFind; goto end; } pFtpFind->FindNextFile(); m_nFtpFileLen = pFtpFind->GetLength(); pFtpFind->Close(); delete pFtpFind; pFtpFile = pFtpConn->OpenFile(m_strFileName.c_str()); if (pFtpFile == NULL) { m_nErrorCode = FTP_SERVER_FILE_OPEN_ERR; goto end; } /*//CInternetFile不支持FTP协议的断点续传,需要自己实现。 if (m_nFtpFileLen != 0) pFtpFile->Seek(m_nDownloadLen, CInternetFile::begin);*/ while(TRUE) { if (!m_bIsStart) break; if (m_nDownloadLen >= m_nFtpFileLen) break; try { nFtpReadSize = pFtpFile->Read(buffer, sizeof(buffer)); } catch (CInternetException * pEx) { TCHAR sz[1024]; pEx->GetErrorMessage(sz, 1024); AfxMessageBox(sz); pEx->Delete(); m_nErrorCode = FTP_SERVER_CONNECT_FAILED; goto end; } if (nFtpReadSize <= 0) continue; try { file.Write(buffer, sizeof(buffer)); }catch(CFileException * pEx) { TCHAR sz[1024]; pEx->GetErrorMessage(sz, 1024); AfxMessageBox(sz); pEx->Delete(); m_nErrorCode = ERR_WRITE_LOCAL_FILE; goto end; } m_nDownloadLen += nFtpReadSize; } end: if (pFtpFile) { pFtpFile->Close(); delete pFtpFile; } if (pFtpConn) { pFtpConn->Close(); delete pFtpConn; } InternetSession.Close(); if (bIsOpenFile) file.Close(); m_bIsStart = FALSE; }