Uploading a list of files from a remote FTP

I am having a problem using the TidFTP component.

I can connect to the server using code like this

vFileList := TStringList.Create;
oClientFTP := TidFTP.Create(nil);
oClientFTP.Port := PortFTP;
oClientFTP.Host := IPHost;
oClientFTP.UserName := UserFTP;
oClientFTP.Password := PasswordFTP;

      

After getting multiple files from StringList (this has exactly 778 elements) when no. 137 an exception is thrown. EIdAcceptTimeout is raised with "Accept time out out". message.

The code I am running is similar to this (works in a thread by the way)

procedure TDownloadFTP.Get;
begin
try
  for I := 0 to vFileList .Count - 1 do
  begin
    sFileName:= vFileList [I];
    posPoint := LastDelimiter('.', sFileName);
    if posPoint = 0 then
      ForceDirectories(ExtractFilePath(Application.ExeName) + '/BackUp/' + sFileName)
    else
      try
        oClienteFTP.Get(sFileName,IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName) + '/BackUp/') + sFileName, True);
    except

      on E: EIdReplyRFCError do
      begin
      end;
      on E: Exception do
        exceptionList.Add(sFileName);
  end;
end;

      

After the exception, the file loads correctly, but this process takes 25 seconds per file (I am downloading 2KB png images).

Any idea on the meaning of this exception?

thank

+3


source to share


2 answers


Googling for EIdAcceptTimeout

leads to this discussion on the Indy forum:

UseHOST in TIdFTP (client) => EIdAcceptTimeout

Where Remy Lebeau states:

The only time this exception can be thrown during data transfer is if you have the TIdFTP.Passive property set to False, which tells the FTP server to connect to TIdFTP inbound. These connections are usually blocked by firewalls / routers that do not support FTP. You usually need to set TIdFTP.Passive = True when you are behind a firewall / router.



So the solution might be for you to add the line

oClientFTP.Passive := True;

      

Btw. In your code snippets, you have both oClientFTP and oClienteFTP. Customize my offer as needed.

+9


source


I would write this as a comment, not an answer, but the comments are too limited. Please let me know and excuse me if I am wrong.

Looking at your code a second time, several questions arise. I see that the StringList can have both files (posPoint <> 0) and presumably directories (posPoint = 0). Is item 137 a file or a directory, and if file, is it the first file after the new directory?

Do the entries in the StringList write the path they should have after '\ backup \?



Assuming your application is a Windows application (since you don't say it otherwise), when you create new paths, why are you using forward slashes (/) instead of backslashes (), which are path separators on Windows? Does your code even create subdirectories on Windows? Well, maybe cross platform Delphi is configurable according to OS.

In the oClienteFTP.Get statement, you are specifying the IncludeTrailingPathDelimiter even if you already have a trailing slash as the trailing delimiter in '/ backup /'.

You no longer have to use "ExtractFilePath (Application.ExeName)" and subdirectories as storage for data files.

+1


source







All Articles