Habe mir vor ein paar Wochen in C (Win32) eins zusammengestoppelt, welches ich aufgrund seiner nicht mehr zu unterbietenden Primitivität liebe.
----------------------------------
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <shellapi.h>
#include <wininet.h>
#include <stdio.h>
char g_szBaseDir[MAX_PATH];
HINTERNET g_hFTP;
char g_szCopyPath[MAX_PATH];
int g_cbTotal = 0;
int g_cbTotalSkip = 0;
int g_zaehler=0;
HANDLE g_hLog = NULL;
char g_szfpb[256];
DWORD g_dwnul = 0;
#define NOTCHANGED 0xfffff304
//-------------------------------------------------------------------
void ReplaceAll(LPTSTR lpsz, LPCTSTR szWhat, LPCTSTR szWith)
{
char bufsr[0x7fff];
ZeroMemory(bufsr, sizeof(bufsr));
LPSTR lpszCurSrch = NULL;
while(lpszCurSrch = strstr(lpsz, szWhat))
{
memcpy(bufsr, lpsz, lpszCurSrch-lpsz);
memcpy(bufsr+(lpszCurSrch-lpsz), szWith, lstrlen(szWith));
memcpy(bufsr+(lpszCurSrch-lpsz)+lstrlen(szWith),
lpszCurSrch+lstrlen(szWhat), lstrlen(lpszCurSrch));
lstrcpy(lpsz, bufsr);
ZeroMemory(bufsr, sizeof(bufsr));
}
}
//-------------------------------------------------------------------
DWORD ULF(LPCSTR lpszLocal)
{
DWORD dwContext = 0;
// printf("sende neue %s ...\r\n", lpszLocal);
// char szDeltaPath[MAX_PATH];
char szRemote[MAX_PATH];
int i = lstrlen(lpszLocal)-1;
while(lpszLocal
!= '\\'
i--;
lstrcpy(szRemote, lpszLocal+i+1);
LPSTR lpszT1 = (LPSTR)lpszLocal;
lpszT1 += lstrlen(g_szBaseDir);
ReplaceAll(lpszT1, "\\", "/"
;
// if(NULL == strstr(lpszT1+1, "\\"
)
// lstrcpy(szDeltaPath, "\\"
;
// else
// memcpy(szDeltaPath, lpszT1, strstr(lpszT1+1, "\\"
-lpszT1);
// BOOL b1 = FtpSetCurrentDirectory(g_hFTP, lpszT1);
/* BOOL b2 = FtpDeleteFile(g_hFTP, lpszT1);
if(!b2)
{
DWORD dwErr = GetLastError();
}
*/
DWORD dwNul;
HANDLE hfL = ::CreateFile(lpszLocal,
GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
DWORD dwLocalSize = GetFileSize(hfL, &dwNul);
CloseHandle(hfL);
WIN32_FIND_DATA fd;
HINTERNET hfind = FtpFindFirstFile(g_hFTP, lpszT1, &fd, INTERNET_FLAG_NO_CACHE_WRITE, dwContext);
if(hfind)
InternetCloseHandle(hfind);
/* if(fd.nFileSizeLow == dwLocalSize)
return NOTCHANGED;
*/
return FtpPutFile(g_hFTP, lpszLocal, lpszT1, FTP_TRANSFER_TYPE_ASCII, dwContext);
}
//-------------------------------------------------------------------
int ProcessDirectory(LPSTR lpszDirectory, int nStartPos)
{
WIN32_FIND_DATA wfd;
HANDLE h;
int nEndPos;
int nNewEndPos;
int nLastDir;
char str[MAX_PATH];
char strPath[MAX_PATH];
char strPath2[MAX_PATH];
char strPathSubPass[MAX_PATH];
lstrcpy(strPath, lpszDirectory);
if(strPath[lstrlen(strPath) - 1] != _T('\\'
)
lstrcat(strPath, "\\"
;
lstrcpy(strPath2, strPath);
lstrcat(strPath, "*.*"
;
h = FindFirstFile(strPath, &wfd);
if(h != INVALID_HANDLE_VALUE)
{
nEndPos = nStartPos;
do
{
if((wfd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY |
FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM))==0
&& (strstr(wfd.cFileName, ".htm"
|| strstr(wfd.cFileName, ".xml"
) )
{
lstrcpy(str, strPath2);
lstrcat(str, wfd.cFileName);
SYSTEMTIME ft2;
SYSTEMTIME st;
BOOL bOggi = FALSE;
FileTimeToSystemTime(&wfd.ftLastWriteTime, &ft2);
GetSystemTime(&st);
if(st.wDay == ft2.wDay
&& st.wMonth == ft2.wMonth
&& st.wYear == ft2.wYear
&& st.wHour - ft2.wHour <= 2)
bOggi = TRUE;
if(!strstr(str, "\\stat"
&& !strstr(str, "\\misz"
&& !strstr(str, "\\navi"
&& bOggi )
{
DWORD dwUlf = ULF(str);
if(dwUlf != 0 && dwUlf != NOTCHANGED)
{
printf("%s\r\n", str);
g_cbTotal++;
}
else if(!dwUlf)
{
printf("FEHLER: %s\r\n", str);
g_cbTotalSkip++;
}
else
{
printf("304: %s\r\n", str);
g_cbTotalSkip++;
}
}
}
} while(FindNextFile(h, &wfd));
}
nLastDir = 0;
h = FindFirstFile(strPath, &wfd);
if(h != INVALID_HANDLE_VALUE)
{
do
{
if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
// ignore the current and parent directory entries
if(lstrcmp(wfd.cFileName, _T("."
) == 0 || lstrcmp(wfd.cFileName, _T(".."
) == 0)
continue;
lstrcpy(strPathSubPass, strPath2);
lstrcat(strPathSubPass, wfd.cFileName);
nNewEndPos = ProcessDirectory(strPathSubPass, nEndPos);
}
} while(FindNextFile(h, &wfd));
}
FindClose(h);
return nEndPos;
}
//-------------------------------------------------------------------
int __cdecl main(int argc, char* argv[])
{
HINTERNET hi = InternetOpen("htmsync 0.01",
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC );
if(hi)
{
DWORD dwContext = 0;
printf("verbinde ftp...\r\n"
;
g_hFTP = InternetConnect(hi, "domain.net",
21, "username", "password", INTERNET_SERVICE_FTP,
TRUE, dwContext);
if(g_hFTP)
{
BOOL bR = FALSE;
//---------------------
DWORD dwTicStart = GetTickCount();
// ZU ERLEDIGEN: Fügen Sie hier den Code ein.
lstrcpy(g_szBaseDir, "d:\\_daten_\\site"
;
ProcessDirectory(g_szBaseDir, 0);
printf("\r\n%d geaendert.\r\n%d nicht geaendert\r\n%d msec",
g_cbTotal, g_cbTotalSkip, GetTickCount()-dwTicStart);
CloseHandle(g_hLog);
//--------------------
InternetCloseHandle(g_hFTP);
printf("fertig\r\n"
;
}
InternetCloseHandle(hi);
}
else
printf("keine verbindung moeglich!"
;
return 0;
}