#include	<Windows.h>
#include	<Wininet.h>
#include	<stdio.h>
#include	<conio.h>

void main()

{

	HINTERNET	InetSession, FtpSession;

	BOOL	InetFlag;

	int		start, finish;
	int		NoTries;

	char	file_in[60], file_out[60], file_from_lis[60];
	char	path_in[30], path_out[30];
	char	file_lis[60];
	char	c;

	FILE	*FileLis=0;

	printf("\n\n******************** DISK2SERVER PROGRAM ***************\n");

	sprintf(file_lis,"%s","c:\\Test\\files_on_disk.lis");
	sprintf(path_out,"%s","/data/themis/");
	
	FileLis = fopen(file_lis,"r");

	InetSession = InternetOpen("My_Program/1.0",
		INTERNET_OPEN_TYPE_DIRECT,
		NULL,
		NULL,
		INTERNET_FLAG_ASYNC);

	FtpSession = InternetConnect(InetSession, 
		"192.168.2.68", 
		INTERNET_DEFAULT_FTP_PORT, 
		"themis", 
		"98izana", 
		INTERNET_SERVICE_FTP,
		INTERNET_FLAG_PASSIVE,
		NULL);

	start = GetTickCount();

	while( fscanf(FileLis,"%s\n",file_from_lis) != EOF)
	{
		sprintf(file_in,"%s",file_from_lis);
		sprintf(file_out,"%s%s",path_out,&file_from_lis[10]);

		InetFlag = 0;
		NoTries = 0;
		while (!InetFlag & NoTries <=100)
		{
			InetFlag = FtpPutFile(FtpSession,
			&file_in, 
			file_out,
			FTP_TRANSFER_TYPE_BINARY,
			NULL);
			NoTries++;
		}
	}

	finish = GetTickCount();
	printf("Elapsed Time %d milliseconds\n",(finish - start));

	InetFlag = InternetCloseHandle(FtpSession);
	InetFlag = InternetCloseHandle(InetSession);

	printf("**************** Press any key to exit *****************\n");
	do {c=getch();}
	while (!c);
	exit(0);
}
