• Domingo 22 de Diciembre de 2024, 09:05

Autor Tema:  Ayuda Con Control Inet  (Leído 1688 veces)

Dieguinho.

  • Miembro MUY activo
  • ***
  • Mensajes: 163
    • Ver Perfil
Ayuda Con Control Inet
« en: Lunes 12 de Febrero de 2007, 19:03 »
0
Buenas.
Estoy intentando averiguar como es el tema de las conexiones a FTP.
De algun lado de internet saque este codigo:

Código: Text
  1.  
  2. Private Sub Command2_Click()
  3. Dim El_Host As String
  4.  
  5.     If txt_Remoto = "" Then
  6.        MsgBox " No hay archivo para descargar", vbInformation
  7.       Exit Sub
  8.     End If
  9.    
  10.         List1.AddItem " ..Descargando "
  11.         'Asigna la Url, es decir el nombre del Host FTP
  12.         El_Host = "ftp://" & txt_servidor
  13.        
  14.     With Inet1
  15.        
  16.         .URL = El_Host
  17.      
  18.         'nombre de usuario y password de la cuanta FTP
  19.         .UserName = txt_Usuario
  20.         .Password = txt_Pass
  21.    
  22.         'DEscarga el archivo indicado con el comando Get
  23.         Call .Execute(, "Get " & txt_Remoto & " " & txt_local)
  24.         DoEvents
  25.        
  26.      End With
  27. End Sub
  28.  
  29.  

Al parecer aca toma un archivo especifico que estaria en el ftp y lo descarga en alguna ruta.
Realmente este ejemplo todavia no lo lleve a la practica, espero que funcione.
Yo lo que quisiera saber es como haria para bajarme todos los archivos que esten dentro de un directorio.

Espero que puedan ayudarme.

Saludos.

Sagutxo

  • Miembro MUY activo
  • ***
  • Mensajes: 320
    • Ver Perfil
Re: Ayuda Con Control Inet
« Respuesta #1 en: Viernes 13 de Abril de 2007, 23:13 »
0
Salu2. Aquí te dejo un ejemplillo:

Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
Const FTP_TRANSFER_TYPE_ASCII = &H1
Const FTP_TRANSFER_TYPE_BINARY = &H2
Const INTERNET_DEFAULT_FTP_PORT = 21               ' default for FTP servers
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_PASSIVE = &H8000000            ' used for FTP connections
Const INTERNET_OPEN_TYPE_PRECONFIG = 0                    ' use registry configuration
Const INTERNET_OPEN_TYPE_DIRECT = 1                        ' direct to net
Const INTERNET_OPEN_TYPE_PROXY = 3                         ' via named proxy
Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4   ' prevent using java/script/INS
Const MAX_PATH = 260
Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String * MAX_PATH
    cAlternate As String * 14
End Type
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Long
Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean
Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hConnect As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Long, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByRef dwContext As Long) As Boolean
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As String, lpdwBufferLength As Long) As Boolean
Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long
Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
Const PassiveConnection As Boolean = True

Private Sub Prueba()

    Dim oConn As Long, hOpen As Long, sOrgPath  As String
    'Apertura de conexión
    hOpen = InternetOpen("Subiendo fotos", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    'Conectar a FTP
    oConn = InternetConnect(hOpen, "IP", Port, "User", "Pass", INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)

    'Creación de buffer para regresar poder regresar al directorio de partida
    sOrgPath = String(MAX_PATH, 0)
    'recojo path del Directorio
    FtpGetCurrentDirectory oConn, sOrgPath, Len(sOrgPath)
    'CREAR UN NUEVO DIR
    FtpCreateDirectory oConn, "testing"
    'POSICIONAMIENTO EN DIECTORIO
    FtpSetCurrentDirectory oConn, "testing"
    'SUBIR FICHERO
    FtpPutFile oConn, "C:\sti.log", "sti.log", FTP_TRANSFER_TYPE_UNKNOWN, 0
    'CAMBIAR NOMBRE al fichero subido
    FtpRenameFile oConn, "sti.log", "sti.lo_"
    'enumera ficheros del directorio
    EnumFiles oConn
    'Me BAJO EL FICHERO
    FtpGetFile oConn, "sti.lo_", "c:\sty.lo_", False, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0
    'BORRAR FICHERO DEL SERVER
    FtpDeleteFile oConn, "apiguide.htm"
    'POSICIONAMIENTO EN EL DIRECTORIO RAIZ
    FtpSetCurrentDirectory oConn, sOrgPath
    'BORRAR CARPETAS
    FtpRemoveDirectory oConn, "testing"
    'CIERRO LA CONEXION a FTP
    InternetCloseHandle oConn
    'CIERRO LA CONEX a INTERNET
    InternetCloseHandle hOpen
'End Sub

   Cogido de un ejemplo de las Apis. espero que te ayude.
 :comp:  :smartass:  :comp:
Mi mujer tiene un físico bárbaro!!!. Einstein.