在DELPHI程序中怎么获取FTP服务器上文件的修改时间?用 NMFTP 控件会获取到如下情况的结果:
修改时间为2003年以前的文件
.   可以获取到文件修改时间的年月日,不能获取到时分秒
修改时间为2003年及2003年以后的文件
.   可以获取到文件修改时间的月日时分,不能获取到年、秒。

解决方案 »

  1.   

    formatDatetime('yyyy-mm-dd hh:mm:ss',idFtp1.DirectoryListing.Items[j].ModifiedDate);我用的是IDFTP, 这个最小是到分, 秒会自动补0. 
      

  2.   

    idFtp1 没有 DirectoryListing 的属性的啊.
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      NMFTP1.Vendor := NMOS_AUTO;
      NMFTP1.Host := '192.0.0.1';
      NMFTP1.UserID := 'xxx';
      NMFTP1.Password := 'xxx';
      NMFTP1.Connect;
      NMFTP1.ParseList := True;
      NMFTP1.Passive := True;
      NMFTP1.List;
      Sleep(2000);
      NMFTP1.Disconnect;
    end;procedure TForm1.NMFTP1ListItem(Listing: String);
    begin
      Memo1.Lines.Add(Listing);
    end;Memo1中就保存了文件名和修改时间以及文件的大小!!!
      

  4.   

    然后你在分析一下Memo1中就内容就行了!!!
      

  5.   

    用 NMFTP 控件会获取到如下情况的结果:
    修改时间为2003年以前的文件
    .   可以获取到文件修改时间的年月日,不能获取到时分秒
    修改时间为2003年及2003年以后的文件
    .   可以获取到文件修改时间的月日时分,不能获取到年、秒。
      

  6.   

    function IsNumericString(const AString : String) : Boolean;
    var
      i, j : Integer;
    begin
      i := 1;
      j := length(AString);
      result := True;
      while i <= j do begin
        if not IsNumeric(AString[i]) then begin
          result := False;
          break;
        end;
        Inc(i);
      end;
    end;procedure TForm1.Calc;
    begin
      InChange := True;  lblYear.Caption := IntToStr(IdDateTimeStamp1.Year);
      txtYear.Text := lblYear.Caption;
      // Hack due to limitation of TUpDown
      udYear.Position := IdDateTimeStamp1.Year div 5;
      if IdDateTimeStamp1.IsLeapYear then begin
        lblIsLeapYear.Caption := 'Yes';
      end else begin
        lblIsLeapYear.Caption := 'No';
      end;  lblDay.Caption := IntToStr(IdDateTimeStamp1.Day);
      txtDay.Text := lblDay.Caption;
      udDay.Position := IdDateTimeStamp1.Day;
      lblDayOfMonth.Caption := IntToStr(IdDateTimeStamp1.DayOfMonth);
      lblDayOfWeek.Caption := IntToStr(IdDateTimeStamp1.DayOfWeek);
      lblDayOfWeekName.Caption := IdDateTimeStamp1.DayOfWeekName + ' / '
        + IdDateTimeStamp1.DayOfWeekShortName;  lblWeekNo.Caption := IntToStr(IdDateTimeStamp1.WeekOfYear);
      udWeek.Position := IdDateTimeStamp1.WeekOfYear + 1;  lblMonthNo.Caption := IntToStr(IdDateTimeStamp1.MonthOfYear);
      udMonth.Position := IdDateTimeStamp1.MonthOfYear + 1;
      lblMonthName.Caption := IdDateTimeStamp1.MonthName + ' / '
        + IdDateTimeStamp1.MonthShortName;  lblSeconds.Caption := IntToStr(IdDateTimeStamp1.Second);
      txtSecond.Text := lblSeconds.Caption;
      // Hack due to limitations of TUpDown control
      udSecond.Position := (IdDateTimeStamp1.Second div 3) + 1;  lblBeatOfDay.Caption := IntToStr(IdDateTimeStamp1.BeatOfDay);  lblMinuteOfDay.Caption := IntToStr(IdDateTimeStamp1.MinuteOfDay);
      udMinuteOfDay.Position := IdDateTimeStamp1.MinuteOfDay + 1;
      lblHourOf12Day.Caption := IntToStr(IdDateTimeStamp1.HourOf12Day);
      udHourOf12Day.Position := IdDateTimeStamp1.HourOf12Day + 2;
      if IdDateTimeStamp1.IsMorning then begin
        lblHourOf12Day.Caption := lblHourOf12Day.Caption + ' (am)';
      end else begin
        lblHourOf12Day.Caption := lblHourOf12Day.Caption + ' (pm)';
      end;
      lblHourOf24Day.Caption := IntToStr(IdDateTimeStamp1.HourOf24Day);
      lblMinuteOfHour.Caption := IntToStr(IdDateTimeStamp1.MinuteOfHour);  lblMilliseconds.Caption := IntToStr(IdDateTimeStamp1.Millisecond);
      udMillisecond.Position := IdDateTimeStamp1.Millisecond + 1;  lblAsRFC822.Caption := IdDateTimeStamp1.GetAsRFC822;  lblAsISO8601Calender.Caption := IDDateTimeStamp1.GetAsISO8601Calendar;
      lblAsISO8601Ordinal.Caption := IDDateTimeStamp1.GetAsISO8601Ordinal;
      lblAsISO8601Week.Caption := IDDateTimeStamp1.GetAsISO8601Week;  InChange := False;
    end;
      

  7.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      If not IsNumericString(txtYear.Text) then begin
        exit;
      end;  if not IsNumericString(txtDay.Text) then begin
        exit;
      end;  Calc;
    end;procedure TForm1.txtYearExit(Sender: TObject);
    begin
      if InChange then exit;  InChange := True;
      if IsNumericString(txtYear.Text) then begin
        IdDateTimeStamp1.SetYear(StrToInt(txtYear.Text));
        Calc;
      end;
      InChange := False;
    end;procedure TForm1.txtDayExit(Sender: TObject);
    begin
      if InChange then exit;  InChange := True;
      if IsNumericString(txtDay.Text) then begin
        IdDateTimeStamp1.SetDay(StrToInt(txtDay.Text));
        Calc;
      end;
      InChange := False;
    end;procedure TForm1.txtDayChange(Sender: TObject);
    begin
      if InChange then exit;  txtDay.Text := Copy(txtDay.Text, 1, 5);
      InChange := True;
      if (IsNumericString(txtDay.Text)) and (txtDay.Text <> '') then begin
        IdDateTimeStamp1.SetDay(StrToInt(txtDay.Text));
        Calc;
      end;
      InChange := False;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      InChange := False;
      FirstTime := True;
      udSecond.Max := SmallInt(IdDateTimeStamp.IdSecondsInDay);
      Calc;
    end;procedure TForm1.txtYearChange(Sender: TObject);
    begin
      if InChange then exit;  // Quick hack to prevent Integer overflow
      txtYear.Text := Copy(txtYear.Text, 1, 5);  InChange := True;
      if (IsNumericString(txtYear.Text)) and (txtYear.Text <> '') then begin
        IdDateTimeStamp1.SetYear(StrToInt(txtYear.Text));
        Calc;
      end;
      InChange := False;
    end;procedure TForm1.txtSecondChange(Sender: TObject);
    begin
      if InChange then exit;  txtSecond.Text := Copy(txtSecond.Text, 1, 5);
      InChange := True;
      if (IsNumericString(txtSecond.Text)) and (txtSecond.Text <> '') then begin
        IdDateTimeStamp1.SetSecond(StrToInt(txtSecond.Text));
        Calc;
      end;
      InChange := False;
    end;procedure TForm1.txtSecondExit(Sender: TObject);
    begin
      if InChange then exit;  InChange := True;
      if IsNumericString(txtSecond.Text) then begin
        udSecond.Position := StrToInt(txtSecond.Text);
      end else begin
        txtSecond.Text := IntToStr(udSecond.Position);
      end;
      Calc;
      InChange := False;
    end;procedure TForm1.FormActivate(Sender: TObject);
    begin
      if FirstTime then begin
        FirstTime := False;
        IdDateTimeStamp1.SetFromTDateTime(Now);
        Calc;
      end;
    end;procedure TForm1.cmdNowClick(Sender: TObject);
    begin
      IdDateTimeStamp1.SetFromTDateTime(Now);
      Calc;
    end;procedure TForm1.cmdResetClick(Sender: TObject);
    begin
      IdDateTimeStamp1.SetYear(1);
      IdDateTimeStamp1.SetDay(1);
      IdDateTimeStamp1.SetSecond(1);
      IdDateTimeStamp1.SetMillisecond(1);
      Calc;
    end;procedure TForm1.udYearClick(Sender: TObject; Button: TUDBtnType);
    begin
      if InChange then exit;  InChange := True;
      if Button = btNext then begin {Up}
        IdDateTimeStamp1.AddYears(1);
      end else if Button = btPrev then begin  {Down}
        IdDateTimeStamp1.SubtractYears(1);
      end;
      Calc;
      InChange := False;
    end;procedure TForm1.udDayClick(Sender: TObject; Button: TUDBtnType);
    begin
      if InChange then exit;  InChange := True;  if Button = btNext then begin {Up}
        IdDateTimeStamp1.AddDays(1);
      end else if Button = btPrev then begin {Down}
        IdDateTimeStamp1.SubtractDays(1);
      end;
      Calc;
      InChange := False;
    end;procedure TForm1.udSecondClick(Sender: TObject; Button: TUDBtnType);
    begin
      if InChange then exit;  InChange := True;  if Button = btNext then begin
        IdDateTimeStamp1.AddSeconds(1); {Up}
      end else if Button = btPrev then begin
        IdDateTimeStamp1.SubtractSeconds(1); {Down}
      end;
      Calc;
      InChange := False;
    end;procedure TForm1.udWeekClick(Sender: TObject; Button: TUDBtnType);
    begin
      if InChange then exit;  InChange := True;  if Button = btNext then begin  {Up}
        IdDateTimeStamp1.AddWeeks(1);
      end else if Button = btPrev then begin  {Down}
        IdDateTimeStamp1.SubtractWeeks(1);
      end;
      Calc;
      InChange := False;
    end;procedure TForm1.udMonthClick(Sender: TObject; Button: TUDBtnType);
    begin
      if InChange then exit;  InChange := True;  if Button = btNext then begin  {Up}
        IdDateTimeStamp1.AddMonths(1);
      end else if Button = btPrev then begin  {Down}
        IdDateTimeStamp1.SubtractMonths(1);
      end;
      Calc;
      InChange := False;
    end;procedure TForm1.udMinuteOfDayClick(Sender: TObject; Button: TUDBtnType);
    begin
      if InChange then exit;  InChange := True;  if Button = btNext then begin {Up}
        IdDateTimeStamp1.AddMinutes(1);
      end else if Button = btPrev then begin {Down}
        IdDateTimeStamp1.SubtractMinutes(1);
      end;
      Calc;
      InChange := False;
    end;procedure TForm1.udHourOf12DayClick(Sender: TObject; Button: TUDBtnType);
    begin
      if InChange then exit;  InChange := True;  if Button = btNext then begin  {Up}
        IdDateTimeStamp1.AddHours(1);
      end else if Button = btPrev then begin {Down}
        IdDateTimeStamp1.SubtractHours(1);
      end;
      Calc;
      InChange := False;
    end;procedure TForm1.udMillisecondClick(Sender: TObject; Button: TUDBtnType);
    begin
      if InChange then exit;  InChange := True;  if Button = btNext then begin {Up}
        IdDateTimeStamp1.AddMilliseconds(1);
      end else begin             {Down}
        IdDateTimeStamp1.SubtractMilliseconds(1);
      end;
      Calc;
      InChange := False;
    end;end.
      

  8.   

    NMFTP1的ListItem事件就有有关该文件的详细信息:修改时间、文件大小procedure TForm1.NMFTP1ListItem(Listing: String);
    begin
      Memo1.Lines.Add(Listing);
    end;
      

  9.   

    用 FTPTREE 可以解决一切问题.真是一个绝好的控件,就是要完全理解它的功能与用途得稍微花点工夫上去,下载地址:
    http://fengyebar.cn.st
    http://soft.winzheng.com/SoftDown.asp?ID=20734