I've setup a simple FTPServer that only serves a specific purpose. Watching the code when a get is performed, I see GetFileDate and GetFileSize called twice, but I never see RetrieveFile being called. Instead, the client shows an exception of 'Connection reset by peer'.
All of the properties of IdFTPServer are default except for AllowAnonymousLogin. 100% of the FTP Server code is being shown:
I've tried changing the TerminateWaitTimeout value, but that didn't help.
__fastcall TFTPServer::TFTPServer(TComponent* Owner) : TDataModule(Owner)
{
root = IncludeTrailingPathDelimiter(GetCurrentDir()) + "files\\";
IdFTPServer1->Active = true;
}
// ---------------------------------------------------------------------------
void __fastcall TFTPServer::Close(void)
{
IdFTPServer1->Active = false;
}
// ---------------------------------------------------------------------------
void __fastcall TFTPServer::IdFTPServer1FileExistCheck(TIdFTPServerContext *ASender, const UnicodeString APathName, bool &VExist)
{
String file = StringReplace(APathName, "/", "", TReplaceFlags() << rfReplaceAll);
TSearchRec sr;
int done = FindFirst(root + file, 0, sr);
VExist = (done == 0);
FindClose(sr);
}
// ---------------------------------------------------------------------------
void __fastcall TFTPServer::IdFTPServer1GetFileDate(TIdFTPServerContext *ASender, const UnicodeString AFilename, TDateTime &VFileDate)
{
String file = StringReplace(AFilename, "/", "", TReplaceFlags() << rfReplaceAll);
TSearchRec sr;
int done = FindFirst(root + file, 0, sr);
if (done == 0)
{
VFileDate = sr.TimeStamp;
}
FindClose(sr);
}
// ---------------------------------------------------------------------------
void __fastcall TFTPServer::IdFTPServer1GetFileSize(TIdFTPServerContext *ASender, const UnicodeString AFilename, __int64 &VFileSize)
{
String file = StringReplace(AFilename, "/", "", TReplaceFlags() << rfReplaceAll);
TSearchRec sr;
int done = FindFirst(root + file, 0, sr);
if (done == 0)
{
VFileSize = sr.Size;
}
FindClose(sr);
}
// ---------------------------------------------------------------------------
void __fastcall TFTPServer::IdFTPServer1RetrieveFile(TIdFTPServerContext *ASender, const UnicodeString AFileName, TStream *&VStream)
{
String file = StringReplace(AFileName, "/", "", TReplaceFlags() << rfReplaceAll);
VStream = new TFileStream(root + file, fmOpenRead);
}
// ---------------------------------------------------------------------------
What am I missing?