Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   SFTP para Delphi 7 ? (https://www.clubdelphi.com/foros/showthread.php?t=82223)

Xavierator 11-02-2013 10:34:55

SFTP para Delphi 7 ?
 
Hola, alguien conoce algun componente o funcion para bajar/subir archivos por SFTP ?

he encontrado esta funcion, pero solo es para FTP: http://www.swissdelphicenter.ch/torr...de.php?id=1095

hay otros componentes, pero son para versiones superiores de Delphi 7

Gracias, Xavi

WkaymQ48 11-02-2013 12:17:19

Puedes usar Curl, mas concretamente la librería libcurl.

Aquí tienes un ejemplo:
http://www.delphiaccess.com/forum/ge...un-ditio-sftp/

Soporta ftps y sftp solamente tendras que indicar el protocolo correspondiente en la url.

Saludos

movorack 11-02-2013 14:59:28

Hola,

Leyendo un poco al respecto, me informo que los componentes indy no manejan SFTP.

en DelphiAccess encontré la siguiente respuesta donde usan CURL para transferir archivos vía SFTP.

Cita:

Empezado por Seoane
Código Delphi [-]
function ReadFromStream(Buffer: PAnsiChar; Size, Count: Integer;
  Stream: TStream): Integer; cdecl;
begin
  Result:= Stream.Read(Buffer^,Size*Count) div Size;
end;
 
function SaveToStream(Buffer: PAnsiChar; Size, Count: Integer;
  Stream: TStream): Integer; cdecl;
begin
  Result:= Stream.Write(Buffer^,Size*Count) div Size;
end;
 
function Subir(Usuario, Clave, URL, Archivo: AnsiString): Boolean;
var
  Curl: TCURL;
  Stream: TFileStream;
begin
  Result:= FALSE;
  Curl:= curl_easy_init;
  if Curl <> nil then
  try
    // Indicamos que muestre mensajes de todo lo que va haciendo
    if curl_easy_setopt(Curl, CURLOPT_VERBOSE, TRUE) <> CURLE_OK then
      Exit;
    // Le decimos que uses SSL
    if curl_easy_setopt(Curl, CURLOPT_USE_SSL, CURLUSESSL_ALL) <> CURLE_OK then
      Exit;
    // No verificamos la identidad del servidor, suponemos que es quien dice ser.
    if curl_easy_setopt(Curl, CURLOPT_SSL_VERIFYPEER, FALSE) <> CURLE_OK then
      Exit;
    // Indicamos el usuario
    if curl_easy_setopt(Curl, CURLOPT_USERNAME, PAnsiChar(Usuario)) <> CURLE_OK then
      Exit;
    // El password
    if curl_easy_setopt(Curl, CURLOPT_PASSWORD, PAnsiChar(Clave)) <> CURLE_OK then
      Exit;
    // La URL del tipo: sftp://servidor/rutadelfichero
    if curl_easy_setopt(Curl, CURLOPT_URL, PAnsiChar(URL)) <> CURLE_OK then
      Exit;
    // Le indicamos que funcion debe usar para leer el stream
    if curl_easy_setopt(Curl, CURLOPT_READFUNCTION, @ReadFromStream) <> CURLE_OK then
      Exit;
    // Creamos un stream a partir de un archivo
    Stream:= TFileStream.Create(Archivo,fmOpenRead);
    try
      // Aqui le indicamos el stream que debe subir
      if curl_easy_setopt(Curl, CURLOPT_INFILE, Stream) <> CURLE_OK then
        Exit;
      // Aqui le indicamos que la operacion es de subida
      if curl_easy_setopt(Curl, CURLOPT_UPLOAD, TRUE) <> CURLE_OK then
        Exit;
      // Ejecutamos el comando
      Result:= curl_easy_perform(Curl) = CURLE_OK;
    finally
      Stream.Free;
    end;
  finally
    curl_easy_cleanup(Curl);
  end;
end;
 
// Sube el archivo "C;\ART.DAT" al servidor con el nombre "2.txt"
  Subir('test','test','sftp://169.254.0.2:999/2.txt','C:\ART.DAT');


movorack 11-02-2013 15:31:08

Mira que me picó el bichito de la curiosidad con este tema y encontré un proyecto en BitBucket llamado Libssh2.

Necesitarás mercurial para obtener el código.

Yo lo estuve revisando un poco aunque no te puedo confirmar si compila en Delphi 7


La franja horaria es GMT +2. Ahora son las 20:39:59.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi