Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Indy FTP Binary upload

359 views
Skip to first unread message

Brian

unread,
Oct 26, 2007, 10:30:22 PM10/26/07
to
Hi

I having a small program with a program that uses Indy (v9) idFTP .

The program uploads a website to a server, it will upload the HTML

or PHP pages fine but not the images.

I swap the Transfer type based on the file by doing the following.

if ((FileExt = '.htm') or (FileExt = '.html') or (FileExt = '.php')) then

FTP.TransferType:= ftASCII else FTP.TransferType := ftBinary;

The images will not upload correctly, even if I change the TransferType to

Binary at design time. It will create the file name on the server, but the
file

normally ends up being about 9 Bytes on and file that should be 1.12Kb

if uploaded via Cute FTP, I must be missing something but I don't know what?

Thnaks

Brian


Nicholas Sherlock

unread,
Oct 26, 2007, 11:14:04 PM10/26/07
to
Brian wrote:
> I must be missing something but I don't know what?

The problem is not with the transfer type. Show the code that loads the
file and uploads it.

Cheers,
Nicholas Sherlock

Brian

unread,
Oct 27, 2007, 8:54:14 AM10/27/07
to

"Nicholas Sherlock" <N.she...@gmail.com> wrote in message
news:ffuadk$dv6$1...@lust.ihug.co.nz...

Thanks for replaying Nicholas,

OK here is the code, it loops though a list of sites and files to upload
them all

if ((FTPHost <> '') or (FTPDIR <> '') or (FTPUser <> '') or (FTPPass <> ''))
then
begin
{*** Connect to server ***}
FTP.Host := FTPHost;
FTP.Username := FTPUser;
FTP.Password := FTPPass;
FTP.Connect(true,5000);
FTP.ChangeDir(FTPDIR);
{** List of FTP sites the files are to be loaded to **}
for k:= 0 to SiteList.Count -1 do
begin
if FTPSubPath.Text = '' then ChangeDir := FTPDIR+'/'+SiteList[k]
else ChangeDir := FTPDIR+'/'+SiteList[k]+'/'+FTPSubPath.Text;
FTP.ChangeDir(ChangeDir);
SitesMemo.Lines.Add('Loading - ' + SiteList[k]);

{** List of files to be uploaded to the server**}
for i:= 0 to FileList.Lines.Count -1 do
begin
theFile:= FileList.Lines.Strings[i];
if AbortNow then
begin
FTP.Disconnect;
StatusBar1.SimpleText := 'Upload Abortted';
SelectBtn.Enabled := True;
RunBtn.Enabled := True;
AbortBtn.Enabled := False;
MainForm.Refresh;
exit;
end;
{** Get and work out file Ext **}
FileExt := ExtractFileExt(theFile);


if ((FileExt = '.htm') or (FileExt = '.html') or (FileExt = '.php'))
then
FTP.TransferType := ftASCII
else FTP.TransferType := ftBinary;

StatusBar1.SimpleText:='Uplaoding '+theFile+' to '+SiteList[k];
FTP.Put(AppDir+SiteList[k]+'\'+theFile,theFile); <<< UPLOAD FILE
HERE
FilesMemo.Lines.Add(ChangeDir+'/'+theFile);
MainForm.Repaint;
end; {** end of files loop **}
SitesMemo.Lines.Delete(k);
SitesMemo.Lines.Add('Finished - ' + SiteList[k]);
FTP.ChangeDir(FTPDIR); {** go back to default DIR **}
end; {** end of site loop **}
FTP.Disconnect;
MainForm.Repaint;

end;


Nicholas Sherlock

unread,
Oct 27, 2007, 8:12:05 PM10/27/07
to
Brian wrote:
> OK here is the code, it loops though a list of sites and files to upload
> them all

Sorry, I can't see any bug in this code :(. The only thing that I could
think of was that 'AppDir+SiteList[k]+'\'+theFile' might not be the
correct full path to the file. Have the program print it out so that you
can ensure that it is correct.

I see in the Indy documentation that setting the file transfer type
wouldn't take effect if the data connection was already established. I'm
not sure if this applies in your case, but you might want to try
removing the assignment that would change the transfer type to ASCII -
text files can be uploaded fine in binary mode too. You could also try
setting FTP.Passive:=true before the loop.

Cheers,
Nicholas Sherlock

Brian

unread,
Nov 2, 2007, 3:56:17 PM11/2/07
to
> Brian wrote:
>> OK here is the code, it loops though a list of sites and files to upload
>> them all
> Nicholas Sherlock wrote

> Sorry, I can't see any bug in this code :(. The only thing that I could
> think of was that 'AppDir+SiteList[k]+'\'+theFile' might not be the
> correct full path to the file. Have the program print it out so that you
> can ensure that it is correct.
>
> I see in the Indy documentation that setting the file transfer type
> wouldn't take effect if the data connection was already established. I'm
> not sure if this applies in your case, but you might want to try removing
> the assignment that would change the transfer type to ASCII - text files
> can be uploaded fine in binary mode too. You could also try setting
> FTP.Passive:=true before the loop.


After a lot of messing about I have found the problem, I'm a Muppet !!!
The file is was meant to be uploading wasn't in the right place !

Thanks for your help Nicholas

Brian


0 new messages