#include "stdafx.h" #include "ftpupdater.h" #include #include CFtpUpdater::CFtpUpdater(bool bIsPassive) { m_hSession = NULL; m_hConnection = NULL; m_bIsPassiveMode = bIsPassive; } CFtpUpdater::~CFtpUpdater() { Disconnect(); } bool CFtpUpdater::Connect(const TCHAR *ip, int port, const TCHAR *userid, const TCHAR *password) { Disconnect(); m_hSession = InternetOpen(_T("Microsoft Internet Explorer"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); if (m_bIsPassiveMode) m_hConnection = InternetConnect(m_hSession, ip, port, userid, password, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0); else m_hConnection = InternetConnect(m_hSession, ip, port, userid, password, INTERNET_SERVICE_FTP, 0, 0); return m_hConnection != NULL ? true : false; } bool CFtpUpdater::SetDirectory(const TCHAR * szPath) { bool check = false; if (m_hConnection) check = FtpSetCurrentDirectory(m_hConnection, szPath) == TRUE ? true : false; return check; } void CFtpUpdater::Disconnect() { if (m_hConnection) InternetCloseHandle(m_hConnection); if (m_hSession) InternetCloseHandle(m_hSession); m_hConnection = 0; m_hSession = 0; } bool CFtpUpdater::DownloadAll(const TCHAR * szDest) { _tmkdir(_T("./PatchFiles")); TCHAR szCreateFolder[256]; _stprintf_s(szCreateFolder, _T("./PatchFiles%s"), szDest); for (int j = 0; (j < sizeof(szCreateFolder)/sizeof(*szCreateFolder)) && szCreateFolder[j] != NULL; j++) if (szCreateFolder[j] == '\\') szCreateFolder[j] = '/'; _tcscpy(_tcsrchr(szCreateFolder, '/'), _T("")); _tmkdir(szCreateFolder); std::vector list; unsigned int i; EnumFileList(_T("."), list); for(i=0; i &list) { HINTERNET hRemoteFile; WIN32_FIND_DATA fd; std::vector folderlist; unsigned int i; TCHAR szFilter[256]; TCHAR szPath[128]; _stprintf_s(szFilter, _T("%s/*.*"), path); hRemoteFile = FtpFindFirstFile(m_hConnection, szFilter, &fd, 0, 0); if (hRemoteFile != NULL) { do { _stprintf_s(szPath, _T("%s/%s"), path, fd.cFileName); if (fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) { if (m_bIsPassiveMode) { if (_tcsstr(szPath, _T("/."))) continue; } folderlist.push_back(szPath); } else { list.push_back(szPath); } } while(InternetFindNextFile(hRemoteFile, &fd) == TRUE); InternetCloseHandle(hRemoteFile); } for(i=0; i 0) fwrite(buffer, readbytes, 1, fp); else break; } } while(1); fclose(fp); InternetCloseHandle(hRemoteFile); // °æ°í : ÀÌ ÇÔ¼ö¿¡¼­ ¸®ÅÏÀÌ ¾ÈµÇ´Â °æ¿ì°¡ ÀÖ´Ù. return true; }