0

I am having trouble using TidFTP to upload a file. The source is a known good zip file and the code below is used to transfer it. It transfers apparently fine and I can use the FTP viewer WinSCP to drag and drop the site copy back to my desktop again but then it will not open with a 'Zip file is invalid' message. The file is about 137k and there is a 3 byte file size difference between the uploaded file and the source, so clearly they are not the same. If I un-comment the verify operation this too returns FALSE.

Can anyone suggest where I might look? I'm using Delphi 10 and Windows 10.

procedure TForm1.Button1Click(Sender: TObject);
var
  FTP : TidFTP;
const
  sSourceFile = 'C:\scratch\hope.zip';
  sDestFolder = '/scratch';
  sDestFileName = 'hope.zip';
begin
  FTP := TidFTP.Create( nil );
  try
    FTP.Host := 'www.mysite.co.uk';
    FTP.Username := 'username';
    FTP.Password := 'password';
    FTP.Passive := True;
    FTP.TransferTimeout := 1000;
    FTP.ConnectTimeout := 2000;
    FTP.ReadTimeout := 3000;

    FTP.Connect();

    FTP.ChangeDir( sDestFolder );
    FTP.Put( sSourceFile, sDestFileName );

    //if not FTP.VerifyFile( sSourceFile, sDestFileName ) then
    //  ShowMessage( 'File verify error' );

    ShowMessage( 'done' );

  finally
    FTP.Disconnect;
    FTP.Free;
  end;
end;
Brian Frost
  • 13,334
  • 11
  • 80
  • 154
  • 7
    Try forcing binary mode. FTP.TransferType := ftBinary; http://stackoverflow.com/questions/1389701/indy-ftp-transfertype – Anthony Eischens Sep 29 '15 at 12:51
  • @Anthony: Perfect that fixed it. Thanks. Make it an answer and I'll accept it. – Brian Frost Sep 29 '15 at 14:04
  • 2
    I've flagged it as a duplicate instead, all I did was apply some ancient knowledge of the FTP protocol and some Google-Fu, can't really claim the answer as my own. Choosing an appropriate duplicate out of many possibilities is the tough part. Thank you though! – Anthony Eischens Sep 29 '15 at 14:42

0 Answers0