Best practice

 

Send file to server via FTP

 

PROCEDURE UploadReportStats(ReportName: String);

VAR

  FtpClient             : TFtpClient;

  FtpOldMode            : TFtpMode;

  DownloadOk            : Boolean;

BEGIN

  New(FtpClient, Create);

  WITH FtpClient DO BEGIN

    FtpOldMode := GetMode;

    SetMode(FTPMODE_PASSIVE);

    Host       := FS;

    UserName   := FU;

    Password   := FP;

    DownloadOk := FALSE;

    IF Connect THEN BEGIN

      { download the stats file as it is }

      IF GetFile(GetVersionId+'\'+IntToStr(GetSysValueInt(6))+'\'+StatsFile,StatsFile,NIL) THEN BEGIN

        { update the stats.ini file }

        New(IniFile, Create);

        WITH IniFile DO BEGIN

          Load(StatsFile);

          ReportRun := ReadBool(IntToStr(GetSerialNo),ReportName,FALSE);

          UserCount := ReadInt(ReportName,'UserCount',0);

          IF ReportRun = FALSE THEN BEGIN

            { new user of this report - upload the updated file }

            WriteBool(IntToStr(GetSerialNo),ReportName,TRUE);

            WriteInt(ReportName,'UserCount',UserCount+1);

            Save(StatsFile);

            { upload the updated file }

            PutFile(StatsFile,GetVersionId+'\'+IntToStr(GetSysValueInt(6))+'\'+StatsFile,NIL);

          END{endif - reportrun 0 false};

        END{endwith};

        Dispose(IniFile, Destroy);

      END{endif - getfile};

      EraseFile(StatsFile);

    END{endif - connect};

    SetMode(FtpOldMode);

  END{endwith};

  Dispose(FtpClient, Destroy);

END;