[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

Problems handling text files with NMFTP and D6

Hello all :)
I do the following:

>> Create Application In Delphi 6
>> Use and setup NMFTP config (hosts/user/pass etc)
>> Set NMFTP file mode to MODE_ASCII
>> Successfully connect and download (GET) a text file from the host

now here's the problem, that text file i just downloaded, if i open it using notepad i can view it normally.
But if i open it in my own delphi application loading it
using a simple memo, rich edit or even using the Read() or EOF() fuctions it shows me crap (something like 'ÏùÔ').

And no its not my computer's problem (eg: not supported chars) because my D6 can read any other non-downloadable files. And another thing, even i that file i downloaded from NMFTP open it and save it inside notepad STILL D6
CANT read it... ok i'm going nuts here guys.

Could anyone explain why this happening and how to solve it?

Thanks in Advance!! :D

0
elissaios
Asked:
elissaios
  • 2
  • 2
1 Solution
 
mocartsCommented:
how do you download file? with NMFTP1.Download(filetoget, filetostore)?
I successfully downloaded my file and it correctly appears in my Memo1. with one exception OnSucces generates Trans_type = cmdUpload instead of cmdDownload :]

code I tested:
..
ftp: TNMFTP;
end;
..
procedure TForm1.Button1Click(Sender: TObject);
begin
  if Button1.Tag = 0 then begin
    ftp.Connect;
    Button1.Tag := 1;
    ftp.Mode(MODE_ASCII);
    ftp.changedir('files');
    Caption := ftp.CurrentDir;
    ftp.Download('jg.css', 'c:\jg.css');
  end else begin
    Button1.Tag := 0;
    ftp.Disconnect;
  end;
end;

procedure TForm1.ftpSuccess(Trans_Type: TCmdType);
begin
  if Trans_Type = cmdUpload then
    memo1.Lines.loadfromfile('C:\jg.css');
end;

connection made with authentication (UserID and password stored in dfm)
mo.
0
 
elissaiosAuthor Commented:
hmmmmmm....

i used exactly the same method :)
the problem's still there...

i connect into my xbox console (yes it can happen since there's a ftp server CVS for it out there) and not in a regular unix/win server.

but i dont think thats the prob, i mean i can upload even
images on it and THEN download them from there and the're intact (valid).

i also noticed that the header of the file has 4 bytes more containing 2 special characters (i guess that for xbox file recognition). i could simply hex edit the file using some fuction before reading it.

but before doing that are there any other ideas/solutions out there? :\
0
 
mocartsCommented:
FF FE (or FE FF) - if you see theses bytes in the begining of your file, then you have deal with Unicode 16. UTF - 8 have 3 bytes in the begining of actual text (EF BB BF) and C4 before each extended (not ANSI) char.

check whether (and which exactly) your file have these encodings by clicking save as and looking in Save As dialog's encoding combobox.

wbr, mo.
0
 
bkuyucuCommented:
I think u should not Set NMFTP file mode to MODE_ASCII,
rather Set NMFTP file mode to MODE_IMAGE that is binary mode. I tried and everything was fine.
Set
NMftp1.Mode(MODE_IMAGE);
before download.


0
 
elissaiosAuthor Commented:
Thank you mo, this was the prob, thanks again :)
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now