• Jueves 28 de Marzo de 2024, 18:42

Autor Tema:  Enviar Base De Datos Via Ftp  (Leído 1367 veces)

willysistemas

  • Miembro activo
  • **
  • Mensajes: 42
    • Ver Perfil
Enviar Base De Datos Via Ftp
« en: Sábado 1 de Marzo de 2008, 04:42 »
0
hola alguien me puede hacer el favor de pasarme un codigo o explicarme como me conecto a un servidor ftp para enviar un backup de la base de datos
Chaka Zulu

Sagutxo

  • Miembro MUY activo
  • ***
  • Mensajes: 320
    • Ver Perfil
Re: Enviar Base De Datos Via Ftp
« Respuesta #1 en: Domingo 23 de Marzo de 2008, 19:00 »
0
Salu2.

Código: Text
  1. Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
  2. Const FTP_TRANSFER_TYPE_ASCII = &H1
  3. Const FTP_TRANSFER_TYPE_BINARY = &H2
  4. Const INTERNET_DEFAULT_FTP_PORT = 21               ' default for FTP servers
  5. Const INTERNET_SERVICE_FTP = 1
  6. Const INTERNET_FLAG_PASSIVE = &H8000000            ' used for FTP connections
  7. Const INTERNET_OPEN_TYPE_PRECONFIG = 0                    ' use registry configuration
  8. Const INTERNET_OPEN_TYPE_DIRECT = 1                        ' direct to net
  9. Const INTERNET_OPEN_TYPE_PROXY = 3                         ' via named proxy
  10. Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4   ' prevent using java/script/INS
  11. Const MAX_PATH = 260
  12. Private Type FILETIME
  13.     dwLowDateTime As Long
  14.     dwHighDateTime As Long
  15. End Type
  16. Private Type WIN32_FIND_DATA
  17.     dwFileAttributes As Long
  18.     ftCreationTime As FILETIME
  19.     ftLastAccessTime As FILETIME
  20.     ftLastWriteTime As FILETIME
  21.     nFileSizeHigh As Long
  22.     nFileSizeLow As Long
  23.     dwReserved0 As Long
  24.     dwReserved1 As Long
  25.     cFileName As String * MAX_PATH
  26.     cAlternate As String * 14
  27. End Type
  28. Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
  29. 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
  30. 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
  31. Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
  32. Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Long
  33. Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
  34. Private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
  35. Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
  36. Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean
  37. 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
  38. 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
  39. Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As String, lpdwBufferLength As Long) As Boolean
  40. 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
  41. Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
  42. Const PassiveConnection As Boolean = True
  43.  
  44. Const SW_NORMAL = 1
  45. 'API De windows
  46.  
  47.  
  48. public Function SubeFich(ValArch as string)
  49.  
  50. Dim oConn As Long, hOpen As Long, sOrgPath  As String, ValStr As String
  51. Dim X
  52.  
  53. 'Apertura de conexión
  54. hOpen = InternetOpen("Subiendo fotos", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
  55. 'Conectar a FTP
  56. oConn = InternetConnect(hOpen, "ftp.patatin.com", PUERTO, "User", "Pass", INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
  57.  
  58. 'Guardo path de entrada
  59.  
  60. sOrgPath = String(MAX_PATH, 0)
  61. FtpGetCurrentDirectory oConn, sOrgPath, Len(sOrgPath)
  62.  
  63. FtpSetCurrentDirectory oConn, "Carpeta que quieras del ftp"
  64.  
  65. FtpPutFile oConn, "Path a fichero de DB, "Nombre de fichero en destino", FTP_TRANSFER_TYPE_UNKNOWN, 0
  66.  
  67. ' Vuelvo a path Origen del FTP
  68. FtpSetCurrentDirectory oConn, sOrgPath
  69.  
  70. 'CIERRO CONEXION a FTP
  71. InternetCloseHandle oConn
  72. 'CIERRO CONEX a INTERNET
  73. InternetCloseHandle hOpen
  74. end function
  75.  
Mi mujer tiene un físico bárbaro!!!. Einstein.