static HINTERNET s_hInternet, s_hFtp;
static BOOL MyFtpConnect()
{
s_hInternet = InternetOpen("FTPTEST", INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0);
if (s_hInternet == NULL) { return FALSE; }
s_hFtp = InternetConnect(s_hInternet, g_Server, INTERNET_DEFAULT_FTP_PORT,
g_User, g_Pass, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
// g_User,g_Pass,INTERNET_SERVICE_FTP,0,0);
if (s_hFtp == NULL) {
InternetCloseHandle(s_hInternet);
return FALSE;
}
return TRUE;
}
static void MyFtpUnConnect()
{
InternetCloseHandle(s_hFtp);
InternetCloseHandle(s_hInternet);
s_hFtp = NULL;
s_hInternet = NULL;
}
static void MyFtpEnumFiles()
{
WIN32_FIND_DATA wfd;
BOOL bResult=TRUE;
HINTERNET hFind;
if (s_hFtp == NULL) return;
hFind = FtpFindFirstFile(s_hFtp,"*.*",&wfd,0,0);
if (hFind != NULL) {
..
while (bResult) {
bResult = InternetFindNextFile(hFind, &wfd);
if (bResult == TRUE) {
..
}
}
InternetCloseHandle(hFind);
}
}
static BOOL MyFtpUpLoad(TCHAR *Path)
{
TCHAR ext[_MAX_EXT];
TCHAR Remote[MAX_PATH];
_splitpath(Path, NULL, NULL, Remote, ext);
lstrcat(Remote,ext);
return FtpPutFile(s_hFtp, Path, Remote,
FTP_TRANSFER_TYPE_BINARY|INTERNET_FLAG_RELOAD, 0);
}
/*
or
static BOOL MyFtpUpLoad(TCHAR *Path)
{
HINTERNET hRemote;
TCHAR ext[_MAX_EXT];
TCHAR Remote[MAX_PATH];
DWORD dwWritten, Prog;
TCHAR buf[1000];
_splitpath(Path, NULL, NULL, Remote, ext);
lstrcat(Remote, ext);
hRemote = FtpOpenFile(s_hFtp, Remote, GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY, 0);
if (hRemote == NULL) return FALSE;
..
Prog=0;
for (;;) {
..
InternetWriteFile(hRemote, buf, 1000, &dwWritten);
Prog+=dwWritten;
..
}
..
InternetCloseHandle(hRemote);
return TRUE;
}
*/
static BOOL MyFtpDownLoad(TCHAR *Path)
{
TCHAR NewFile[MAX_PATH];
wsprintf(NewFile, "c:\\%s", Path);
return FtpGetFile(s_hFtp, Path, NewFile, FALSE, FILE_ATTRIBUTE_NORMAL,
FTP_TRANSFER_TYPE_BINARY|INTERNET_FLAG_RELOAD, 0);
}
/*
or
static BOOL MyFtpDownLoad(TCHAR *Path)
{
HINTERNET hRemote;
DWORD dwRead, dwWritten, Prog;
BOOL Result;
TCHAR NewFile[MAX_PATH];
TCHAR buf[1000];
TCHAR str[255];
hRemote = FtpOpenFile(s_hFtp, Path, GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 0);
if (hRemote == NULL) return FALSE;
..
for (;;) {
Result = InternetReadFile(hRemote, buf, 1000, &dwRead);
if ((Result == TRUE) && (dwRead == 0)) break;
..
}
..
InternetCloseHandle(hRemote);
return TRUE;
}
*/