Thema: Delphi FTP status anzeige

Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#12

Re: FTP status anzeige

  Alt 18. Mai 2007, 02:08
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.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat