Autor Beitrag
SebTheRipper
Hält's aus hier
Beiträge: 11



BeitragVerfasst: Fr 21.02.03 09:22 
Also, zuerst einmal: ich bin noch mehr so ein einsteiger im gebiet der programmiersprachen, progge seit einem halben jahr mit delphi!
und da habe ich jetzt mal eine Frage:
Und zwar möchte ich den inhalt einer textdatei(zb:test.txt) von einem ftp server aus laden zb: "ftp://test:test@ftp.tripod.de/test.txt" bzw auch darauf wieder speichern, zugriffsrechtsprobleme dürfte es dabei doch nicht geben weil ich userid und passwort ja im pfad angebe! aber wie mache ich das in delphi ( am besten mit memo oder richedit)
Da ich Einsteiger bin wäre es nett wenn einer mir das auf rechts simplem wege erklären könnte, auch wenn es dann vielleicht ein bisschen weniger vorteile hat! wichtig ist nur das es geladen und gespeichert werden kann und gegebenenfalls vielleicht verändert!
normal würde ich eine textdatei über memo1.lines.loadfromfile(*.txt); laden aber dann zeigt er mir eine EFOpen fehlermeldung!

Vielen Dank im vorraus

SebTheRipper

Moderiert von user profile iconTino: Signatur entfernt.
Ex0rzist
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 550

Win XP Prof.
Mandrake 10.0

D6
BeitragVerfasst: Fr 21.02.03 15:51 
Hallo Seb,

schau dir doch mal die Indy-Komponenten an. Dort gibt es jeweils auch ein Beispiel zu HTTP und FTP.

Um die Datei in einem Memo zu öffnen, muss sie erstmal runtergeladen werden.
Das machst du mit den Indy-Komponenten. Dort kann man dann auch m.E. Username und Passwort eingeben.

_________________
If accidentally read, induce vomitting.
SebTheRipper Threadstarter
Hält's aus hier
Beiträge: 11



BeitragVerfasst: Fr 21.02.03 18:07 
Titel: Und wie mache ich das jetzt genau...??
wie gesagt ich bin noch ein anfänger im gegensatz zu euch anderen!
also ich habe jetzt die idftp komponente genommen Tidftp
und wie rufe ich das jetzt über einen button zum beispiel auf das er die datei runterläd oder hochläd?

vielleicht auch noch ein paar einstellungen angeben bei user habe ich username bei password das pass und bei host ftp.tripod.de

ps: zusätzliche uses anzugeben wäre auch sehr nett :)

pps: ich habe es jetzt auf einem anderen wege hinbekommen die datei runterzuladen, brauche nur noch den upload auf den ftp!

ppps: kann man auch eine datei direkt editieren? also memo1.lines.add['ftp-adresse']!

Vielen Dank für deine Antwort und alle die folgen mögen!

SebTheRipper
Ex0rzist
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 550

Win XP Prof.
Mandrake 10.0

D6
BeitragVerfasst: Fr 21.02.03 20:17 
Hallo Seb,

schau doch bitte mal in deinem Delphi-Ordner unter Demos/Indy/FTP-Demo nach. Dort findest du ein ausführliches Beispiel zum Thema Indy und FTP.

Dann brauchst du dir nur noch die Sachen raussuchen, die du brauchst. 8)

SebTheRipper hat folgendes geschrieben:
ppps: kann man auch eine datei direkt editieren? also memo1.lines.add['ftp-adresse']!


Nein, das ist nicht möglich. Ein bisschen arbeiten muss man schon.

_________________
If accidentally read, induce vomitting.
lippi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: So 23.02.03 09:37 
bei tripod kannst du sowieso nichts ansehen wenn du das direkt verlinkst, die haben so ein blocker reingebaut.
Cyrus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mo 24.02.03 10:09 
Vielleicht hilft das:

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
uses 
  WinInet, ComCtrls; 

function FtpDownloadFile(strHost, strUser, strPwd: string; 
  Port: Integer; ftpDir, ftpFile, TargetFile: string; ProgressBar: TProgressBar): Boolean; 

  function FmtFileSize(Size: Integer): string; 
  begin 
    if Size >= $F4240 then 
      Result := Format('%.2f', [Size / $F4240]) + ' Mb' 
    else 
    if Size < 1000 then 
      Result := IntToStr(Size) + ' bytes' 
    else 
      Result := Format('%.2f', [Size / 1000]) + ' Kb'; 
  end; 

const 
  READ_BUFFERSIZE = 4096;  // or 256, 512, ... 
var 
  hNet, hFTP, hFile: HINTERNET; 
  buffer: array[0..READ_BUFFERSIZE - 1] of Char; 
  bufsize, dwBytesRead, fileSize: DWORD; 
  sRec: TWin32FindData; 
  strStatus: string; 
  LocalFile: file; 
  bSuccess: Boolean; 
begin 
  Result := False; 

  { Open an internet session } 
  hNet := InternetOpen('Program_Name', // Agent 
                        INTERNET_OPEN_TYPE_PRECONFIG, // AccessType 
                        nil,  // ProxyName 
                        nil, // ProxyBypass 
                        0); // or INTERNET_FLAG_ASYNC / INTERNET_FLAG_OFFLINE 

  { 
    Agent contains the name of the application or 
    entity calling the Internet functions 
  } 


  { See if connection handle is valid } 
  if hNet = nil then 
  begin 
    ShowMessage('Unable to get access to WinInet.Dll'); 
    Exit; 
  end; 

  { Connect to the FTP Server } 
  hFTP := InternetConnect(hNet, // Handle from InternetOpen 
                          PChar(strHost), // FTP server 
                          port, // (INTERNET_DEFAULT_FTP_PORT), 
                          PChar(StrUser), // username 
                          PChar(strPwd),  // password 
                          INTERNET_SERVICE_FTP, // FTP, HTTP, or Gopher? 
                          0, // flag: 0 or INTERNET_FLAG_PASSIVE 
                          0);// User defined number for callback 

  if hFTP = nil then 
  begin 
    InternetCloseHandle(hNet); 
    ShowMessage(Format('Host "%s" is not available',[strHost])); 
    Exit; 
  end; 

  { Change directory } 
  bSuccess := FtpSetCurrentDirectory(hFTP, PChar(ftpDir)); 

  if not bSuccess then 
  begin 
    InternetCloseHandle(hFTP); 
    InternetCloseHandle(hNet); 
    ShowMessage(Format('Cannot set directory to %s.',[ftpDir])); 
    Exit; 
  end; 

  { Read size of file } 
  if FtpFindFirstFile(hFTP, PChar(ftpFile), sRec, 0, 0) <> nil then 
  begin 
    fileSize := sRec.nFileSizeLow; 
    // fileLastWritetime := sRec.lastWriteTime 
  end else 
  begin 
    InternetCloseHandle(hFTP); 
    InternetCloseHandle(hNet); 
    ShowMessage(Format('Cannot find file ',[ftpFile])); 
    Exit; 
  end; 

  { Open the file } 
  hFile := FtpOpenFile(hFTP, // Handle to the ftp session 
                       PChar(ftpFile), // filename 
                       GENERIC_READ, // dwAccess 
                       FTP_TRANSFER_TYPE_BINARY, // dwFlags 
                       0); // This is the context used for callbacks. 

  if hFile = nil then 
  begin 
    InternetCloseHandle(hFTP); 
    InternetCloseHandle(hNet); 
    Exit; 
  end; 

  { Create a new local file } 
  AssignFile(LocalFile, TargetFile); 
  {$i-} 
  Rewrite(LocalFile, 1); 
  {$i+} 

  if IOResult <> 0 then 
  begin 
    InternetCloseHandle(hFile); 
    InternetCloseHandle(hFTP); 
    InternetCloseHandle(hNet); 
    Exit; 
  end; 

  dwBytesRead := 0; 
  bufsize := READ_BUFFERSIZE; 

  while (bufsize > 0) do 
  begin 
    Application.ProcessMessages; 

    if not InternetReadFile(hFile, 
                            @buffer, // address of a buffer that receives the data 
                            READ_BUFFERSIZE, // number of bytes to read from the file 
                            bufsize) then Break; // receives the actual number of bytes read 

    if (bufsize > 0) and (bufsize <= READ_BUFFERSIZE) then 
      BlockWrite(LocalFile, buffer, bufsize); 
    dwBytesRead := dwBytesRead + bufsize; 

    { Show Progress } 
    ProgressBar.Position := Round(dwBytesRead * 100 / fileSize); 
    Form1.Label1.Caption := Format('%s of %s / %d %%',[FmtFileSize(dwBytesRead),FmtFileSize(fileSize) ,ProgressBar.Position]); 
  end; 

  CloseFile(LocalFile); 

  InternetCloseHandle(hFile); 
  InternetCloseHandle(hFTP); 
  InternetCloseHandle(hNet); 
  Result := True; 
end;

Greez Cyrus

_________________
Wer glaub er ist, hört auf zu werden!
Delphi Rulez!!!
Cyrus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mo 24.02.03 10:15 
oder sonst verwende doch einfach die von delphi mitgelieferte NMFTP Komponente! Es hat sogar ein mitgeliefertes Beispiel dabei! ist meisst im delphi ordner unter demos dann im ordner fastnet

Greez Cyrus

_________________
Wer glaub er ist, hört auf zu werden!
Delphi Rulez!!!