|
|
ビルド時に 、wininet.lib が必要になります
| |
|
|
// *********************************************************
// デフォルトコンストラクタ
// *********************************************************
LboxWininet::LboxWininet()
{
LboxWininet::hSession = NULL;
LboxWininet::hConnect = NULL;
LboxWininet::bPassive = false;
LboxWininet::Agent.operator = ( "lightbox" );
}
// *********************************************************
// デストラクタ
// *********************************************************
LboxWininet::~LboxWininet()
{
if ( LboxWininet::hConnect != NULL ) {
InternetCloseHandle( LboxWininet::hConnect );
}
if ( LboxWininet::hSession != NULL ) {
InternetCloseHandle( LboxWininet::hSession );
}
}
| |
|
|
|
|
// *********************************************************
// FTP 接続
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::FTPConnect( )
{
LboxWininet::Disconnect( );
this->hSession = InternetOpen(
this->Agent.szLboxString,
INTERNET_OPEN_TYPE_DIRECT,
NULL, NULL, 0
);
if ( this->hSession == NULL ) {
return false;
}
DWORD nPassive;
nPassive = 0;
if ( this->bPassive ) {
nPassive = INTERNET_FLAG_PASSIVE;
}
this->hConnect = InternetConnect(
this->hSession,
this->Server.szLboxString,
INTERNET_INVALID_PORT_NUMBER,
this->User.szLboxString,
this->Password.szLboxString,
INTERNET_SERVICE_FTP,
nPassive,
NULL
);
if ( this->hConnect == NULL ) {
InternetCloseHandle( this->hSession );
return false;
}
return true;
}
| |
|
|
|
|
// *********************************************************
// 接続解除
// 戻り値 : 無し
// *********************************************************
void LboxWininet::Disconnect( )
{
if ( this->hConnect != NULL ) {
InternetCloseHandle( this->hConnect );
}
if ( this->hSession != NULL ) {
InternetCloseHandle( this->hSession );
}
}
| |
|
|
|
|
// *********************************************************
// FTP ダウンロード
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::FTPDownload( LboxString *LRemote, LboxString *LLocal )
{
return LboxWininet::FTPDownload(
LRemote->szLboxString,
LLocal->szLboxString
);
}
BOOL LboxWininet::FTPDownload( LPTSTR lpRemote, LPTSTR lpLocal )
{
BOOL bRet;
bRet = FtpGetFile(
this->hConnect,
lpRemote,
lpLocal,
false,
FILE_ATTRIBUTE_NORMAL,
FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_RELOAD,
NULL
);
return bRet;
}
| |
|
|
|
|
// *********************************************************
// FTP アップロード
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::FTPUpload( LboxString *LRemote, LboxString *LLocal )
{
return LboxWininet::FTPUpload(
LRemote->szLboxString,
LLocal->szLboxString
);
}
BOOL LboxWininet::FTPUpload( LPTSTR lpRemote, LPTSTR lpLocal )
{
BOOL bRet;
bRet = FtpPutFile(
this->hConnect,
lpLocal,
lpRemote,
FTP_TRANSFER_TYPE_BINARY,
NULL
);
return bRet;
}
| |
|
|
|
|
// *********************************************************
// FTP カレントディレクトリ設定
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::FTPSetCurrentDirectory( LboxString *LDir )
{
return LboxWininet::FTPSetCurrentDirectory(
LDir->szLboxString
);
}
BOOL LboxWininet::FTPSetCurrentDirectory( LPTSTR lpDir )
{
return FtpSetCurrentDirectory(
this->hConnect,
lpDir
);
}
| |
|
|
|
|
// *********************************************************
// FTP カレントディレクトリ取得
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::FTPGetCurrentDirectory( LboxString *LDir )
{
if ( LDir->nLboxString < MAX_PATH ) {
LDir->Resize( MAX_PATH );
}
DWORD dwSize;
dwSize = LDir->nLboxString;
return FtpGetCurrentDirectory(
this->hConnect,
LDir->szLboxString,
&dwSize
);
}
| |
|
|
|
|
// *********************************************************
// FTP ディレクトリ作成
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::FTPCreateDirectory( LboxString *LDir )
{
return LboxWininet::FTPCreateDirectory(
LDir->szLboxString
);
}
BOOL LboxWininet::FTPCreateDirectory( LPTSTR lpDir )
{
return FtpCreateDirectory(
this->hConnect,
lpDir
);
}
| |
|
|
|
|
// *********************************************************
// FTP ディレクトリ削除
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::FTPRemoveDirectory( LboxString *LDir )
{
return LboxWininet::FTPRemoveDirectory(
LDir->szLboxString
);
}
BOOL LboxWininet::FTPRemoveDirectory( LPTSTR lpDir )
{
return FtpRemoveDirectory(
this->hConnect,
lpDir
);
}
| |
|
|
|
|
// *********************************************************
// FTP ファイルの名称変更
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::FTPRenameFile( LboxString *LOld, LboxString *LNew )
{
return LboxWininet::FTPUpload(
LOld->szLboxString,
LNew->szLboxString
);
}
BOOL LboxWininet::FTPRenameFile( LPTSTR lpOld, LPTSTR lpNew )
{
return FtpRenameFile(
this->hConnect,
lpOld,
lpNew
);
}
| |
|
|
|
|
// *********************************************************
// FTP ファイル削除
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::FTPDeleteFile( LboxString *LFile )
{
return LboxWininet::FTPDeleteFile(
LFile->szLboxString
);
}
BOOL LboxWininet::FTPDeleteFile( LPTSTR lpFile )
{
return FtpDeleteFile(
this->hConnect,
lpFile
);
}
| |
|
|
|
|
// *********************************************************
// FTP ファイルサイズ取得
// 戻り値 : サイズ ( エラーの場合は -1 )
// *********************************************************
DWORD LboxWininet::FTPGetFileSize( LboxString *LFile )
{
return LboxWininet::FTPGetFileSize(
LFile->szLboxString
);
}
DWORD LboxWininet::FTPGetFileSize( LPTSTR lpFile )
{
WIN32_FIND_DATA wfd;
HINTERNET hRet;
hRet = FtpFindFirstFile(
this->hConnect,
lpFile,
&wfd,
INTERNET_FLAG_RELOAD,
NULL
);
if ( hRet == NULL ) {
return -1;
}
return wfd.nFileSizeLow;
}
| |
|
|
|
|
// *********************************************************
// FTP ファイル最終書き込み日付・時間の取得
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::FTPGetLastWriteTime( LboxString *LFile, LboxString *LDate )
{
return LboxWininet::FTPGetLastWriteTime(
LFile->szLboxString,
LDate
);
}
BOOL LboxWininet::FTPGetLastWriteTime( LPTSTR lpFile, LboxString *LDate )
{
WIN32_FIND_DATA wfd;
SYSTEMTIME st;
HINTERNET hRet;
hRet = FtpFindFirstFile(
this->hConnect,
lpFile,
&wfd,
INTERNET_FLAG_RELOAD,
NULL
);
if ( hRet == NULL ) {
return false;
}
FileTimeToSystemTime(
&(wfd.ftLastWriteTime),
&st
);
LDate->Printf(
"%04d/%02d/%02d %02d:%02d:%02d",
st.wYear,
st.wMonth,
st.wDay,
st.wHour,
st.wMinute,
st.wSecond
);
return true;
}
| |
|
|
|
|
// *********************************************************
// FTP ファイル一覧の取得
// ファイル名には "" か ワイルドカードを指定して下さい
// 戻り値 : true 成功, false データ無し
// *********************************************************
BOOL LboxWininet::FTPEnum(
LboxString *LDir, LboxString *LFile, LboxListview *Lview )
{
return LboxWininet::FTPEnum(
LDir->szLboxString,
LFile->szLboxString,
Lview
);
}
BOOL LboxWininet::FTPEnum(
LPTSTR lpDir, LPTSTR lpFile, LboxListview *Lview )
{
Lview->Initialize();
Lview->AddColumn( LVCFMT_LEFT, 100, "" );
Lview->AddColumn( LVCFMT_LEFT, 100, "ファイル名" );
Lview->AddColumn( LVCFMT_LEFT, 100, "最終更新" );
Lview->AddColumn( LVCFMT_LEFT, 100, "属性" );
Lview->AddColumn( LVCFMT_LEFT, 100, "サイズ" );
Lview->AddColumn( LVCFMT_LEFT, 100, "作成日" );
Lview->AddColumn( LVCFMT_LEFT, 100, "最終アクセス" );
HINTERNET hFind;
LboxString Local;
WIN32_FIND_DATA wfd;
SYSTEMTIME st;
int nCnt;
BOOL bRet;
Local.operator = (lpDir);
Local.operator += ("/");
Local.operator += (lpFile);
hFind = NULL;
nCnt = 0;
while( 1 ) {
if ( hFind == NULL ) {
hFind = FtpFindFirstFile(
this->hConnect,
Local.szLboxString,
&wfd,
INTERNET_FLAG_RELOAD,
NULL
);
if ( hFind == NULL ) {
return false;
}
}
else {
bRet = InternetFindNextFile(
hFind,
&wfd
);
if ( !bRet ) {
break;
}
}
Lview->AddRow();
nCnt++;
Lview->SetColumnPrintf( 0, "%d", nCnt );
Lview->SetColumnText( 1, wfd.cFileName );
FileTimeToSystemTime(
&(wfd.ftLastWriteTime),
&st
);
Local.Printf(
"%04d/%02d/%02d %02d:%02d:%02d",
st.wYear,
st.wMonth,
st.wDay,
st.wHour,
st.wMinute,
st.wSecond
);
if ( Local.operator != ("1601/01/01 00:00:00") ) {
Lview->SetColumnText( 2, &Local );
}
Lview->SetColumnPrintf( 3, "%X", wfd.dwFileAttributes );
Lview->SetColumnPrintf( 4, "%ld", wfd.nFileSizeLow );
FileTimeToSystemTime(
&(wfd.ftCreationTime),
&st
);
Local.Printf(
"%04d/%02d/%02d %02d:%02d:%02d",
st.wYear,
st.wMonth,
st.wDay,
st.wHour,
st.wMinute,
st.wSecond
);
if ( Local.operator != ("1601/01/01 00:00:00") ) {
Lview->SetColumnText( 5, &Local );
}
FileTimeToSystemTime(
&(wfd.ftLastAccessTime),
&st
);
Local.Printf(
"%04d/%02d/%02d %02d:%02d:%02d",
st.wYear,
st.wMonth,
st.wDay,
st.wHour,
st.wMinute,
st.wSecond
);
if ( Local.operator != ("1601/01/01 00:00:00") ) {
Lview->SetColumnText( 6, &Local );
}
}
Lview->Fit();
return true;
}
| |
|
|
|
|
// *********************************************************
// HTTP 接続
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::HTTPConnect( )
{
LboxWininet::Disconnect( );
this->hSession = InternetOpen(
this->Agent.szLboxString,
INTERNET_OPEN_TYPE_DIRECT,
NULL, NULL, 0
);
if ( this->hSession == NULL ) {
return false;
}
this->hConnect = InternetConnect(
this->hSession,
this->Server.szLboxString,
INTERNET_INVALID_PORT_NUMBER,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
NULL
);
if ( this->hConnect == NULL ) {
InternetCloseHandle( this->hSession );
return false;
}
return true;
}
| |
|
|
|
|
// *********************************************************
// HTTP GET (BODY部の取得)
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::HTTPGet( LPTSTR lpTarget, LboxString *LData )
{
HINTERNET hHttp;
if ( this->hConnect == NULL ) {
return false;
}
hHttp = HttpOpenRequest(
this->hConnect,
NULL,
lpTarget,
"HTTP/1.1",
NULL,
NULL,
INTERNET_FLAG_RELOAD | INTERNET_FLAG_KEEP_CONNECTION,
0
);
if ( hHttp == NULL ) {
return false;
}
if ( !( HttpSendRequest( hHttp, NULL, 0, NULL, 0 )) ) {
InternetCloseHandle( hHttp );
return false;
}
BOOL bLoop;
DWORD dwByte;
DWORD dwOffset;
DWORD nLen;
dwOffset = 0;
nLen = LData->nLboxString;
bLoop = true;
while( bLoop ) {
bLoop = InternetReadFile(
hHttp,
LData->szLboxString + dwOffset,
nLen,
&dwByte
);
if ( dwByte == 0 ) {
break;
}
LData->szLboxString[dwOffset+dwByte] = 0x00;
LData->Resize( LData->nLboxString + MAX_PATH );
dwOffset = dwOffset + dwByte;
nLen = MAX_PATH;
}
InternetCloseHandle( hHttp );
return true;
}
| |
|
|
|
|
// *********************************************************
// HTTP GET (HEADER部の取得)
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::HTTPGetHeader( LPTSTR lpTarget, LboxString *LData )
{
HINTERNET hHttp;
if ( this->hConnect == NULL ) {
return false;
}
hHttp = HttpOpenRequest(
this->hConnect,
NULL,
lpTarget,
"HTTP/1.1",
NULL,
NULL,
INTERNET_FLAG_RELOAD | INTERNET_FLAG_KEEP_CONNECTION,
0
);
if ( hHttp == NULL ) {
return false;
}
if ( !( HttpSendRequest( hHttp, NULL, 0, NULL, 0 )) ) {
InternetCloseHandle( hHttp );
return false;
}
BOOL bRet;
DWORD dwByte;
DWORD nLen;
nLen = LData->nLboxString;
dwByte = 0;
bRet = HttpQueryInfo(
hHttp,
HTTP_QUERY_RAW_HEADERS_CRLF,
LData->szLboxString,
&nLen,
&dwByte
);
if ( !bRet ) {
if ( GetLastError() == ERROR_INSUFFICIENT_BUFFER ) {
LData->Resize( nLen+1 );
nLen = LData->nLboxString;
dwByte = 0;
bRet = HttpQueryInfo(
hHttp,
HTTP_QUERY_RAW_HEADERS_CRLF,
LData->szLboxString,
&nLen,
&dwByte
);
}
}
InternetCloseHandle( hHttp );
return bRet;
}
// *********************************************************
// HTTP GET (HEADERの個別取得)
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxWininet::HTTPGetHeader(
LPTSTR lpTarget, DWORD dwInfoLevel, LboxString *LData )
{
HINTERNET hHttp;
if ( this->hConnect == NULL ) {
return false;
}
hHttp = HttpOpenRequest(
this->hConnect,
NULL,
lpTarget,
"HTTP/1.1",
NULL,
NULL,
INTERNET_FLAG_RELOAD | INTERNET_FLAG_KEEP_CONNECTION,
0
);
if ( hHttp == NULL ) {
return false;
}
if ( !( HttpSendRequest( hHttp, NULL, 0, NULL, 0 )) ) {
InternetCloseHandle( hHttp );
return false;
}
BOOL bRet;
DWORD dwByte;
DWORD nLen;
nLen = LData->nLboxString;
dwByte = 0;
bRet = HttpQueryInfo(
hHttp,
dwInfoLevel,
LData->szLboxString,
&nLen,
&dwByte
);
if ( !bRet ) {
if ( GetLastError() == ERROR_INSUFFICIENT_BUFFER ) {
LData->Resize( nLen+1 );
nLen = LData->nLboxString;
dwByte = 0;
bRet = HttpQueryInfo(
hHttp,
HTTP_QUERY_RAW_HEADERS_CRLF,
LData->szLboxString,
&nLen,
&dwByte
);
}
}
InternetCloseHandle( hHttp );
return bRet;
}
| |
|
|
|