Delphi-PRAXiS
Seite 2 von 2     12   

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 18. Mai 2007 01:53

Re: FTP status anzeige
 
schande ueber mich..

vielen dank =D

Luckie 18. Mai 2007 02: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 09: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 12: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 05: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 10:46 Uhr.
Seite 2 von 2     12   

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 by Thomas Breitkreuz