|
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
|
|