#include #include #include #pragma comment(lib, "wininet.lib") int main() { HINTERNET hInternet; HINTERNET hFtpSession; HINTERNET hFind; WIN32_FIND_DATAW fd; // WIN32_FIND_DATAWを使用することに注意 /* WININETの初期化 */ hInternet = InternetOpen( L"WININET Sample Program", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); if (hInternet == NULL) { wprintf(L"InternetOpen failed\n"); return 1; } /* ftps.biglobe.ne.jpへ接続 */ hFtpSession = InternetConnect( hInternet, L"ftps.biglobe.ne.jp", INTERNET_DEFAULT_FTP_PORT, L"*****", L"*****", INTERNET_SERVICE_FTP, 0, 0); if (hFtpSession == NULL) { wprintf(L"InternetConnect failed\n"); InternetCloseHandle(hInternet); return 1; } /* ファイルを列挙し、表示 */ hFind = FtpFindFirstFile(hFtpSession, L"/public_html/", &fd, 0, 0); if (hFind != NULL) { do { wprintf(L"%s\n", fd.cFileName); } while (InternetFindNextFile(hFind, &fd)); // hFindを閉じる InternetCloseHandle(hFind); } else { DWORD error = GetLastError(); wprintf(L"FtpFindFirstFile failed with error code: %d\n", error); } /* 後処理 */ InternetCloseHandle(hFtpSession); InternetCloseHandle(hInternet); return 0; }