IdFTPServer异常“对等重置连接”

时间:2019-01-15 23:24:14

标签: c++builder indy10 ftp-server

我已经设置了一个仅用于特定目的的简单FTPServer。观看执行获取的代码,我看到GetFileDate和GetFileSize被调用了两次,但是我从未看到RetrieveFile被调用。而是,客户端显示“对等方重置连接”的例外。

除AllowAnonymousLogin之外,IdFTPServer的所有属性都是默认属性。正在显示100%的FTP服务器代码:

我尝试更改TerminateWaitTimeout值,但这无济于事。

__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);
}

// ---------------------------------------------------------------------------

我想念什么?

0 个答案:

没有答案