|
|
// *********************************************************
// 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;
}
| |
|
|
|
|
// *********************************************************
// 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::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;
}
| |
|
|
|