conexión ftp con archivo key y chilkat

(1/1)

gisierra:
SOS! actualmente nos conectamos a un servidor mediante  SFTP por chilkat, enviando 4 parámetros que son el dominio, puerto, usuario y clave.
Sucede que ahora que cambiaron el proveedor la clave lo envían con un archivo KEY y no se como leerlo. El software esta en BV6.0

código actual que si funciona:

========================================
Public Function Subre_GUIA(nombreArchivo As String) As Integer
Dim sftp As New ChilkatSFtp
Dim success As Long

success = sftp.UnlockComponent("TALMAS.SS1122018_6FYzL2ydm7mF")

If (success <> 1) Then
    Subre_GUIA = 1
    Exit Function
End If

sftp.ConnectTimeoutMs = 5000
sftp.IdleTimeoutMs = 10000

success = sftp.Connect(gIPFTP_Guia, gPuertoFTP_Guia)
If (success <> 1) Then
    Subre_GUIA = 1
    Exit Function
End If

success = sftp.AuthenticatePw(gUsuarioFTP_Guia, gPasswordFTP_Guia)

If (success <> 1) Then
    Subre_GUIA = 1
    Exit Function
End If

success = sftp.InitializeSftp()
If (success <> 1) Then
    Subre_GUIA = 1
    Exit Function
End If

success = sftp.UploadFileByName("IN/" & nombreArchivo & ".txt", App.Path + "\IN\" & nombreArchivo & ".txt")
If (success <> 1) Then
    Subre_GUIA = 1
    Exit Function
End If

sftp.Disconnect

If (success <> 1) Then
    Subre_GUIA = 1
    Exit Function
End If

Subre_GUIA = 0

End Function
========================
pero no se como setear el password desde el archivo

TickTack:
Quizás ya solucionaste el problema. Pero si no, ya que quiero volver a entrar en el mundo de la programación:

Código:

Public Function Subre_GUIA(nombreArchivo As String) As Integer
    Dim sftp As New ChilkatSFtp
    Dim success As Long
    Dim clave As String
   
    success = sftp.UnlockComponent("TALMAS.SS1122018_6FYzL2ydm7mF")

    If (success <> 1) Then
        Subre_GUIA = 1
        Exit Function
    End If

    sftp.ConnectTimeoutMs = 5000
    sftp.IdleTimeoutMs = 10000

    success = sftp.Connect(gIPFTP_Guia, gPuertoFTP_Guia)
    If (success <> 1) Then
        Subre_GUIA = 1
        Exit Function
    End If

    ' Leer el contenido del archivo KEY y usarlo como clave
    clave = LeerContenidoArchivo("ruta_del_archivo.key")

    success = sftp.AuthenticatePw(gUsuarioFTP_Guia, clave)

    If (success <> 1) Then
        Subre_GUIA = 1
        Exit Function
    End If

    success = sftp.InitializeSftp()
    If (success <> 1) Then
        Subre_GUIA = 1
        Exit Function
    End If

    success = sftp.UploadFileByName("IN/" & nombreArchivo & ".txt", App.Path + "\IN\" & nombreArchivo & ".txt")
    If (success <> 1) Then
        Subre_GUIA = 1
        Exit Function
    End If

    sftp.Disconnect

    If (success <> 1) Then
        Subre_GUIA = 1
        Exit Function
    End If

    Subre_GUIA = 0

End Function

Function LeerContenidoArchivo(rutaArchivo As String) As String
    Dim fso As Object
    Dim archivo As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set archivo = fso.OpenTextFile(rutaArchivo)
    LeerContenidoArchivo = archivo.ReadAll
    archivo.Close
    Set archivo = Nothing
    Set fso = Nothing
End Function


Este código modificado incluye una función adicional llamada LeerContenidoArchivo que se encarga de leer el contenido del archivo KEY. Asegúrate de reemplazar "ruta_del_archivo.key" con la ruta correcta hacia el archivo KEY en tu sistema. Luego, la clave leída se utiliza para autenticarse en el servidor SFTP en lugar de la contraseña directamente.

Navegación

[0] Índice de Mensajes