Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi FTP status anzeige (https://www.delphipraxis.net/92298-ftp-status-anzeige.html)

1234588 17. Mai 2007 16:19


FTP status anzeige
 
hallo community ;)
ich hab hier eine funktion gefunden die es einem erleichtert einen upload einer datei zu realisieren. da ich im grunde nur eine datei habe die auf einen server muss, sehe ich es nicht ein zu den indys oder anderem zu greifen. da die datei von 100kb bis rund 5 mb groß sein kann, waere eine status anzeige ganz nett.
leider funktioniert das ganze nicht wie ich moechte.
(das beep() im callback dient nur zu testzwecken)

Delphi-Quellcode:
procedure StatusCallback(hInet: HINTERNET; Context, Status: DWORD; pInformation: Pointer; InfoLength: DWORD); stdcall;
begin
  beep(100, 100);
end;

function PutFile(server, username, password, localfile, remotefile: string; port: word = 21): boolean;
var
  hopen, hconnect: HINTERNET;
begin
  hopen := InternetOpen('test', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);
  InternetSetStatusCallback(hopen, @StatusCallback);
  hconnect := InternetConnect(hopen, pchar(server), port, pchar(username), pchar(password), INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
  Result := FtpPutFile(hconnect, pchar(localfile), pchar(remotefile), FTP_TRANSFER_TYPE_UNKNOWN, 0);
  InternetCloseHandle(hconnect);
end;
ich freue mich ueber jede hilfe die mich ein steuck weit weiter bringt

inherited 17. Mai 2007 16:37

Re: FTP status anzeige
 
Zitat:

Zitat von 1234588
da ich im grunde nur eine datei habe die auf einen server muss, sehe ich es nicht ein zu den indys oder anderem zu greifen.

Und wieso nicht?

1234588 17. Mai 2007 16:43

Re: FTP status anzeige
 
weil ich mein programm eigentlich weitgehend komponentenfrei halten wollte. ;)

inherited 17. Mai 2007 22:41

Re: FTP status anzeige
 
Sorry für die dummen Fragen, aber warum? :lol:
Du kannst die Komponente ja dynamisch erstellen wenn du sie brauchst.

1234588 17. Mai 2007 23:29

Re: FTP status anzeige
 
weil ich alles nur noch mit meiner status anzeige verbinden muesste (ich verwende PROGRESS_CLASS), was kein großes problem darstellen sollte. das jetzt auf die indys umbauen waere viel mehr arbeit :P
mir waere das ganze ohne indy lieber, wenn mir aber keiner helfen kann bzw. mir niemand sagen kann was ich falsch mache, muss ich wohl alles umschreiben :'(

fkerber 17. Mai 2007 23:37

Re: FTP status anzeige
 
Hi!

Zitat:

Zitat von 1234588
leider funktioniert das ganze nicht wie ich moechte.


Was funktioniert denn nicht?
Bzw. inwiefern äußert sich das "geht nicht"?
Was hast du bisher versucht?


Ciao, Frederic

1234588 17. Mai 2007 23:47

Re: FTP status anzeige
 
ich moechte eine status anzeige haben. ich habe in meiner callback() prozedur die moeglichkeit den fortschritt meines uploads auszulesen (so meine ich zumindest). normalerweise sollte beep() beim upload ausgeloest werden, was aber nicht passiert (beep() habe ich nur zu testzwecken). ich komm einfach nicht dahinter was ich falsch gemacht habe

fkerber 18. Mai 2007 00:06

Re: FTP status anzeige
 
Hi!

Dann schau mal hier, was die Code-Lib zu bieten hat:
http://www.delphipraxis.net/internal...ct.php?t=88375

oder auch hier:
http://support.microsoft.com/kb/234913


Ciao, Frederic

1234588 18. Mai 2007 00:19

Re: FTP status anzeige
 
ich denke das ich das umschreiben kann

vielen dank ;)

(ich werde das umgeschriebene dann hier veroeffentlichen)

Luckie 18. Mai 2007 00:28

Re: FTP status anzeige
 
Wer lesen kann ist klar im Vorteil:
Zitat:

Note The callback function specified in the lpfnInternetCallback parameter will not be called on asynchronous operations for the request handle when the dwContext parameter of HttpOpenRequest is set to zero (INTERNET_NO_CALLBACK), or the connection handle when the dwContext handle of InternetConnect is set to zero (INTERNET_NO_CALLBACK).

1234588 18. Mai 2007 00:53

Re: FTP status anzeige
 
schande ueber mich..

vielen dank =D

Luckie 18. Mai 2007 01:08

Re: FTP status anzeige
 
Delphi-Quellcode:
uses
  Windows,
  WinInet,
  WinSock,
  SysUtils;

procedure StatusCallback(hInet: HINTERNET; Context, Status: DWORD; pInformation: Pointer; InfoLength: DWORD); stdcall;
var
  s                : string;
begin
  case Status of
    INTERNET_STATUS_CLOSING_CONNECTION: s := 'Closing the connection to the server';
    INTERNET_STATUS_CONNECTED_TO_SERVER: s := 'Successfully connected to the socket address: ' + IntToStr((sockaddr_in(pInformation).sin_port));
    INTERNET_STATUS_CONNECTING_TO_SERVER: s := 'Connecting to the socket address';
    INTERNET_STATUS_CONNECTION_CLOSED: s := 'Successfully closed the connection to the server';
//    INTERNET_STATUS_COOKIE_HISTORY: s := 'Retrieving content from the cache.';
//    INTERNET_STATUS_COOKIE_RECEIVED: s := 'Indicates the number of cookies';
//    INTERNET_STATUS_COOKIE_SENT: s := 'number of cookies that were either sent or suppressed';
    INTERNET_STATUS_CTL_RESPONSE_RECEIVED: s := 'Not implemented';
//    INTERNET_STATUS_DETECTING_PROXY: s := 'Notifies the client application that a proxy has been detected.';
    INTERNET_STATUS_HANDLE_CLOSING: s := 'This handle value has been terminated';
    INTERNET_STATUS_HANDLE_CREATED: s := 'InternetConnect has created the new handle';
    INTERNET_STATUS_INTERMEDIATE_RESPONSE: s :=
      'Received an intermediate (100 level) status code message from the server';
    INTERNET_STATUS_NAME_RESOLVED: s := 'Successfully found the IP address: ' + PChar(pInformation);
//    INTERNET_STATUS_P3P_HEADER: s := 'The response has a P3P header in it.';
//    INTERNET_STATUS_P3P_POLICYREF: s := 'Not implemented.';
    INTERNET_STATUS_PREFETCH: s := 'Not implemented';
//    INTERNET_STATUS_PRIVACY_IMPACTED: s := 'Not implemented.';
    INTERNET_STATUS_RECEIVING_RESPONSE: s := 'Waiting for the server to respond to a request ';
    INTERNET_STATUS_REDIRECT: s := 'HTTP request is about to automatically redirect the request ' +
      PChar(pInformation);
    INTERNET_STATUS_REQUEST_COMPLETE: s := 'An asynchronous operation has been completed';
    INTERNET_STATUS_REQUEST_SENT: s := 'Successfully sent the information request to the server: ' +
      IntToStr(Integer(pInformation)) + ' Byte';
    INTERNET_STATUS_RESOLVING_NAME: s := 'Looking up the IP address: ' + PChar(pInformation);
    INTERNET_STATUS_RESPONSE_RECEIVED: s := 'Successfully received a response from the server: ' +
      IntToStr(Integer(pInformation)) + ' Byte';
    INTERNET_STATUS_SENDING_REQUEST: s := 'Sending the information request to the server.';
    INTERNET_STATUS_STATE_CHANGE:
      begin
        s := 'Moved between a secure (HTTPS) and a nonsecure (HTTP) site.';
        case DWORD(pInformation) of
          INTERNET_STATE_CONNECTED: s := s + #13#10 + 'Connected state. Mutually exclusive with disconnected state.';
          INTERNET_STATE_DISCONNECTED: s := s + #13#10 +
            'Disconnected state. No network connection could be established.';
          INTERNET_STATE_DISCONNECTED_BY_USER: s := s + #13#10 + 'Disconnected by user request.';
          INTERNET_STATE_IDLE: s := s + #13#10 + 'No network requests are being made by Windows Internet.';
          INTERNET_STATE_BUSY: s := s + #13#10 + 'Network requests are being made by Windows Internet.';
//          INTERNET_STATUS_USER_INPUT_REQUIRED: s := s + #13#10 + 'he request requires user input to be completed.';
        end;
      end;
  end;
  Writeln(s);
end;

function PutFile(server, username, password, localfile, remotefile: string; port: word = 21): boolean;
var
  hopen, hconnect  : HINTERNET;
begin
  hopen := InternetOpen('test', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);
  if Assigned(hopen) then
  begin
    InternetSetStatusCallback(hopen, @StatusCallback);
    hconnect := InternetConnect(hopen, pchar(server), port, pchar(username), pchar(password), INTERNET_SERVICE_FTP,
      INTERNET_FLAG_PASSIVE, 1);
    if Assigned(hconnect) then
    begin
      Result := FtpPutFile(hconnect, pchar(localfile), pchar(remotefile), FTP_TRANSFER_TYPE_UNKNOWN, 1);
      InternetCloseHandle(hconnect);
    end
    else
      Result := False;
  end
  else
    Result := False;
end;

begin
  if not PutFile('michael-puff.de', 'l3s11195', 'wd8y7rcv', 'd:\CU_A1804.SAV', 'html/CU_A1804.SAV') then
    Writeln(SysErrorMessage(GetLastError));
  Writeln('Done');
  Readln;
end.
So geht es bis auf Zeile 13, da meint er ungültiger Typecast. Wenn sich das hjmand noch mal angucken könnte? Da müsste in pInformation ein Zeiger auf eine sockaddr_in Struktur stehen mit der man Adresse und Port bestimmen kann. Das hab eich aber leider nicht hinbekommen.

CCRDude 18. Mai 2007 08:36

Re: FTP status anzeige
 
sockaddr_in ist doch auch ein Record und kein Zeiger auf jenes? Da solltest Du wahrscheinlich eher ein PSockAddrIn verwenden...

Luckie 18. Mai 2007 11:46

Re: FTP status anzeige
 
Ah, ja. Dann geht es, aber meine Demo zeigt mir als Port 13358 an, ein Portmonitor aber 1089 bzw 1092. :gruebel: Und wie kommt man über diese Information an die IP-Adresse dran?

Sunlight7 25. Mai 2007 04:46

Re: FTP status anzeige
 
Moin!

Da ich grad den Code von jemanden überarbeite, der diese Callback eingebaut hat.
Der Typecast ist falsch:

Delphi-Quellcode:
IntToStr(Integer(pInformation)) + ' Byte';
Das macht einen Integer aus der Pointeradresse

Delphi-Quellcode:
IntToStr(Integer(pInformation^)) + ' Byte';
So klappts dann auch mit dem Nachbarn.


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:39 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz