Murugan.com
Murugan Andezuthu Dharmaratnam

  |  HOME   |  BLOG   |  TWITTER   |  ARTICLES   |  8086  |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  PHP   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  



VC++ Win32 FTP Sessions Client Application


Home  > VC++  > VC++ Win32 FTP Sessions Client Application 
       
I was trying to build a small ftp client application using vc++ win32 I had earlier buitl similar 
applications to download file using wininethttp. Here are some useful notes. 




WinINet enables applications to navigate and manipulate directories and files on an ftp server.

This is how you start coding 

First use Internetopen to which initiates the use of the windows inet function


   HINTERNET hSession = InternetOpen("Leedhar FTP",
                                      INTERNET_OPEN_TYPE_PRECONFIG,
                                      NULL,
                                      NULL,
                                      0);
	if(hSession == NULL )
	{
		char * str;
		str=(char*)malloc(1000);
		MsgBox(_ltoa(GetLastError(),str,16));
	}



InternetConnect to create the session handle. which opens an FTP Session


    HINTERNET hConnection = InternetConnect(hInternet, 
                                            strServer,  // Server
                                            INTERNET_DEFAULT_FTP_PORT,
                                            lpszUsername,     // Username
                                            lpszPassword,     // Password
                                            INTERNET_SERVICE_FTP,
                                            INTERNET_SERVICE_FTP,        // Synchronous
                                            NULL);    // No Context

	if(hConnection == NULL )
	{
		char * str;
		str=(char*)malloc(1000);
		MsgBox(_ltoa(GetLastError(),str,16));
	}


Next Navigation is provided by the FtpGetCurrentDirectory and FtpSetCurrentDirectory functions. 
These functions utilize the session handle created by a previous call to InternetConnect to determine 
which directory the application is currently in, or to change to a different subdirectory.

		char * lpszCurrentDirectory;
		lpszCurrentDirectory=(char*)malloc(1000);
		if(FtpGetCurrentDirectory(hConnect,lpszCurrentDirectory,lpdwCurrentDirectory)==false)
		{
			char * str;
			str=(char*)malloc(1000);
			MsgBox(_ltoa(GetLastError(),str,16));
		}
		return lpszCurrentDirectory;


We can perform Directory enumeration by using the FtpFindFirstFile and InternetFindNextFile functions.


Find first file

WIN32_FIND_DATA	 sFindFirst;
hInternet = FtpFindFirstFile(hInternet,NULL,&sFindFirst,NULL,NULL);
MsgBox(sFindFirst.cFileName);


			while(InternetFindNextFile(hInternet,(void*)&sFindFirst))
			{
				MsgBox(sFindFirst.cFileName);
			}		



In case U are wondering what this MsgBox is doing insted of MessageBox Here's the code

HWND hWid;
void MsgBox(char* msg)
{
	MessageBox(hWid,msg,msg,0);
}


Once U get a hold of doing this remain things u dont need my code they are pretty easy

.Net VC File IO Sample Code

activex mdb

com smartcard

COM variant Data type

DirectX Store Video as mpeg

GetLastError() in VC++ Win32 Display the Value in a MessageBox

GetWindowName() VC++ Win32 Get a Window Name Given Handle

index

multi threaded socket

shellexecute open internet explorer

VC Win32 Tree View Control Change Background color of tree

VC++ 6.0 Win32 SetParent () Add an Existing Window as child window of another or Dynamically add a child window or Assign Window to a parent

VC++ 6.0 Win32 Splitter control like SplitContainer in .Net

VC++ 6.0 Win32 What are the Different Windows Controls That are Available in Win32 Non MFC

VC++ DWORD To String

VC++ Error LNK2001 unresolved external symbol public static

VC++ Win32 compare string with empty character constant

VC++ Win32 Compress Video To Mpeg

VC++ Win32 Exit Application

VC++ Win32 FTP Sessions Client Application

VC++ WIn32 IP from domain name

VC++ win32 Listview Get Selected Item

VC++ win32 ListView or LIST Control how to scroll to a list or make sure that a list item is visible

VC++ Win32 ListView SelectedItem()

VC++ Win32 Open in Internet explorer or firefox

Does Windows have an Inbuild FileExist function API



  |  HOME   |  BLOG   |  TWITTER   |  ARTICLES   |  8086  |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  PHP   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  

Copyright 2009 @ Murugan Andezuthu Dharmaratnam