|
#include <windows.h>
#include <wininet.h>
#include <stdio.h>
#pragma comment( lib, "wininet.lib " )
HINTERNET hSession;
HINTERNET hConnect;
DWORD nByte = 0;
int nCnt = 0;
void CALLBACK StatusFunc(
HINTERNET hInternet,
DWORD Context,
DWORD Status,
LPVOID StatusInfo,
DWORD StatusInfoSize)
{
if ( Status == INTERNET_STATUS_RESPONSE_RECEIVED ) {
nByte += *((DWORD *)StatusInfo);
nCnt++;
if ( nCnt % 20 == 0 ) {
printf("* " );
}
}
}
int main(int argc, char* argv[])
{
hSession = InternetOpen(
"lightbox",
INTERNET_OPEN_TYPE_DIRECT,
NULL, NULL, 0
);
if ( hSession == NULL ) {
printf("InternetOpen error\n");
return 0;
}
InternetSetStatusCallback( hSession, StatusFunc );
DWORD nPassive;
nPassive = INTERNET_FLAG_PASSIVE;
hConnect = InternetConnect(
hSession,
"bekins.borland.com",
INTERNET_INVALID_PORT_NUMBER,
"anonymous",
"user@domian",
INTERNET_SERVICE_FTP,
nPassive,
NULL
);
if ( hConnect == NULL ) {
InternetCloseHandle( hSession );
printf("InternetConnect error\n");
return 0;
}
BOOL bRet;
bRet = FtpGetFile(
hConnect,
"/groups/jp/cppbuild/freecommandlinetools2.exe",
"freecommandlinetools2.exe",
false,
FILE_ATTRIBUTE_NORMAL,
FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_RELOAD,
1
);
if ( bRet ) {
printf("\nダウンロードが完了しました\n");
}
else {
printf("\nダウンロードが失敗しました\n");
}
InternetCloseHandle( hConnect );
InternetCloseHandle( hSession );
return 0;
}
| |