#include #include #include #pragma comment(lib, "wininet.lib") // FTPファイルの更新日時を取得する関数 BOOL FtpGetFileTime(HINTERNET hConnect, LPFILETIME lpLastWriteTime, DWORD dwReserved, DWORD_PTR dwContext) { // FTPファイルのパス LPCTSTR lpszFileName = _T("/public_html/errors.txt"); // FTPファイルの情報を取得する WIN32_FIND_DATA findData; HINTERNET hFind = FtpFindFirstFile(hConnect, lpszFileName, &findData, INTERNET_FLAG_RELOAD, dwContext); if (hFind != NULL) { // 更新日時を設定 FileTimeToLocalFileTime(&findData.ftLastWriteTime, lpLastWriteTime); // 検索ハンドルを閉じる InternetCloseHandle(hFind); return TRUE; } return FALSE; } int main() { HINTERNET hInternet; HINTERNET hFtpSession; /* WININETの初期化 */ hInternet = InternetOpen( L"WININET Sample Program", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); /* FTPセッションの確立 */ hFtpSession = InternetConnect( hInternet, L"ftps.biglobe.ne.jp", INTERNET_DEFAULT_FTP_PORT, L"*****", L"*****", INTERNET_SERVICE_FTP, 0, 0); // ファイルの更新日時を取得する FILETIME lastModifiedTime = { 0 }; // FILETIME 構造体を0で初期化 if (FtpGetFileTime(hFtpSession, &lastModifiedTime, 0, (DWORD_PTR)NULL)) { SYSTEMTIME stUTC, stLocal; FileTimeToSystemTime(&lastModifiedTime, &stUTC); SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal); _tprintf(_T("File Last Modified Time: %04d-%02d-%02d %02d:%02d:%02d\n"), stLocal.wYear, stLocal.wMonth, stLocal.wDay, stLocal.wHour, stLocal.wMinute, stLocal.wSecond); } else { _tprintf(_T("FtpGetFileTime failed (%d)\n"), GetLastError()); } // 接続を閉じる InternetCloseHandle(hFtpSession); InternetCloseHandle(hInternet); return 0; }