1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
int check_ftp()
{
HINTERNET hInternet = NULL;
HINTERNET hFtpConnect = NULL;
HINTERNET hFile = NULL;
char newVer[256];
string oldVer;
DWORD byte;
fstream f;
TCHAR tchHost[MAX_PATH] = TEXT("HostName");
TCHAR tchUser[MAX_PATH] = TEXT("UserName");
TCHAR tchPwd[MAX_PATH] = TEXT("MDP");
TCHAR tchName[MAX_PATH] = TEXT("/depot/version.txt");
hInternet = InternetOpen(TEXT(""), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hInternet == NULL)
return (1);
hFtpConnect = InternetConnect(hInternet, tchHost, INTERNET_DEFAULT_FTP_PORT, tchUser, tchPwd, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
if (hFtpConnect == NULL)
return (1);
hFile = FtpOpenFile(hFtpConnect, tchName, GENERIC_READ, FTP_TRANSFER_TYPE_ASCII | INTERNET_FLAG_RELOAD, 0);
//ErrorExit("FtpOpenFile");
if (hFile == NULL)
return (1);
if (InternetReadFile(hFile, &newVer, 256, &byte))
{
f.open(VER_TXT, fstream::in);
getline(f, oldVer);
f.close();
}
InternetCloseHandle(hFile);
InternetCloseHandle(hFtpConnect);
InternetCloseHandle(hInternet);
return (0);
} |
Partager