I am writing a simple Delphi7/FPC compatible console application in
order to use in a daily task to transfer a backup zipfile from a
server to my Windows 7 laptop. The task is a bat script that does a
lot of other stuff as well as the FTP and it has been a struggle
setting ftp up for batch file operation so I decided to write this
console app to better integrate into the bat file.

To this end I have  the following code (only showing the relevant
stuff:

uses
  SysUtils,
  Classes,
  IdFTP,
  IdComponent,
  IniFiles;

var
  FTP: TIdFTP;
  FTPHost,
  FTPUser,
  FTPPwd: string;
  FTPPort: word;
  FList: TStringList;
...

function ConnectFTP: boolean;
begin
  Result := false;
  try
    if FTP.Connected then
    begin
      LogMessage('Already connected to ' + FTPHost);
      Result := true;
      exit;
    end;

    FTP.Host := FTPHost;  //remote server by computer name
    FTP.Port := FTPPort;  //remote port is 2121
    FTP.Username := FTPUser;  //Windows username
    FTP.Password := FTPPwd;   //Windows password

    FTP.Connect;

    if not FTP.Connected then
    begin
      LogError('Could not connect by FTP');
    end
    else
      LogMessage('Connected to ' + FTPHost);
    Result := FTP.Connected;
  except
    on E: Exception do
      LogException(E.Message);
  end;
end;

procedure ListFiles(var Lst: TStringList);
{Get a directory listing of remote ftp server's current dir}
var
  Res: string;
begin
  if not FTP.Connected then
    ConnectFTP;
  if not FTP.Connected then
    exit;
  try
    FTP.List(Res); // <== EXCEPTION HERE!
    Lst.Text := Res;
    LogMessage(Lst.Text);
  except
    on E: Exception do
      LogException(E.Message);
  end;
end;

....

begin
  FTP := TIdFTP.Create;
  FList := TStringList.Create;
  try
    GetConfig; //Retrieve configuration from ini file
    LogMessage('Starting FTP transfer from ' + FTPHost);
    if not ConnectFTP then
    begin
      LogError('Could not connect to ' + FTPHost + ' on port ' +
IntToStr(FTPPort));
      ExitCode := 1;
      Exit;
    end;
  //Now read directory on target
  ListFiles(FList);
.... more code here ....
  LogMessage('Finished transfer');
  finally
    FList.Free;
    if FTP.Connected then
      FTP.Disconnect;
    FTP.Free;
  end;
end.

What I get is an exception in my logfile saying: 

20:14:01.018 EXCEPTION: Invalid PORT Command.

I have tried to trace it into the Indy sources but I get lost there
and as soon as I release the execution I have the exception trigger.

The FTP server is on a Windows Server 2003 and it works OK using
FileZilla and the Windows built-in FTP client as well as a FTP testing
utility I have build years ago.
From this utility I have basically cut the code shown above and yet I
get the error when trying FTP.List()...

Normally when dealing with Indy errors I post on the Embarcadero Forum
Delphi.Internet.Winsock using a newsreader. THen I usually get replies
from Remy Lebeau.
But now it seems like the Embarcadero servers have crashed again so
the forums are down.
Hence I am hoping for some help here...


-- 
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to