![]() |
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:
ich freue mich ueber jede hilfe die mich ein steuck weit weiter bringt
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; |
Re: FTP status anzeige
Zitat:
|
Re: FTP status anzeige
weil ich mein programm eigentlich weitgehend komponentenfrei halten wollte. ;)
|
Re: FTP status anzeige
Sorry für die dummen Fragen, aber warum? :lol:
Du kannst die Komponente ja dynamisch erstellen wenn du sie brauchst. |
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 :'( |
Re: FTP status anzeige
Hi!
Zitat:
Was funktioniert denn nicht? Bzw. inwiefern äußert sich das "geht nicht"? Was hast du bisher versucht? Ciao, Frederic |
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
|
Re: FTP status anzeige
Hi!
Dann schau mal hier, was die Code-Lib zu bieten hat: ![]() oder auch hier: ![]() Ciao, Frederic |
Re: FTP status anzeige
ich denke das ich das umschreiben kann
vielen dank ;) (ich werde das umgeschriebene dann hier veroeffentlichen) |
Re: FTP status anzeige
Wer lesen kann ist klar im Vorteil:
Zitat:
|
Re: FTP status anzeige
schande ueber mich..
vielen dank =D |
Re: FTP status anzeige
Delphi-Quellcode:
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.
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. |
Re: FTP status anzeige
sockaddr_in ist doch auch ein Record und kein Zeiger auf jenes? Da solltest Du wahrscheinlich eher ein PSockAddrIn verwenden...
|
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?
|
Re: FTP status anzeige
Moin!
Da ich grad den Code von jemanden überarbeite, der diese Callback eingebaut hat. Der Typecast ist falsch:
Delphi-Quellcode:
Das macht einen Integer aus der Pointeradresse
IntToStr(Integer(pInformation)) + ' Byte';
Delphi-Quellcode:
So klappts dann auch mit dem Nachbarn.
IntToStr(Integer(pInformation^)) + ' Byte';
|
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