S
S
SHAKIRA2014-09-25 01:20:12
Delphi
SHAKIRA, 2014-09-25 01:20:12

Why can't this function of sending files to FTP be written in Delphi?

procedure FTPUpload();
var IdFTP:TIdFtp;
   dn:integer;
   F: TSearchRec;
    ftpset:TstringList;
      ftphost, ftpport, ftplogin, ftppassword, ftpdir: String;
begin
ftpset:=TStringList.Create;
   ftpset.LoadFromFile(dir+'/ftp.txt');
 ftphost:=Copy(ftpset[0], 6, length(ftpset[0]));
 ftpport:=Copy(ftpset[1], 6, length(ftpset[1]));
 ftplogin:=Copy(ftpset[2], 7, length(ftpset[2]));
  ftppassword:=Copy(ftpset[3], 10, length(ftpset[3]));
   ftpdir:=Copy(ftpset[4], 11, length(ftpset[4]));
   Form1.Label1.Caption:= 'Зарузка файлов на FTP сервер...';
 try
   IdFTP:=TIdFTP.Create(nil);
   if IdFTP.Connected then
     begin
      IdFTP.Abort;
      IdFTP.Quit;
     end;
   IdFTP.Username := ftplogin;
   IdFTP.Password := ftppassword;
   IdFTP.Host := ftphost;
   try
      IdFTP.Connect;
      if IdFTP.Connected then
        begin
         IdFTP.ChangeDir(ftpdir);
         chdir(dir+'\acestream');
         dn := FindFirst('*.*',faArchive,F);
         while dn = 0 do

           begin
             IdFTP.Put(dir+'\acestream\'+f.name,f.name, True);
             dn := FindNext(F);

           end;
         //IdFTP.Quit;
        end;
      Form1.Label1.Caption:= 'Зарузка файлов на FTP сервер...';
   except
      ShowMessage('Ошибка отправки.');
   end;
 finally
   IdFTP.Free;
 end;

end;

I run it on a timer. But having worked 1 time, she does not want to work. Tried adding idFTP.Disconnect; but gives nothing. Stops in the area
if IdFTP.Connected then
     begin
      IdFTP.Abort;
      IdFTP.Quit;
     end;

But if you remove it, then nothing will change. How to fix it? Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexP11223, 2014-09-25
@AlexP11223

And what's the point of checking Connected and trying to complete it on a freshly created object?
How exactly does it not work? Exception? Which?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question