J'ai des problemes avec un ftp...

cs_miamia Messages postés 3 Date d'inscription jeudi 21 août 2003 Statut Membre Dernière intervention 27 août 2003 - 21 août 2003 à 16:37
xmanuxs Messages postés 4 Date d'inscription jeudi 9 septembre 2004 Statut Membre Dernière intervention 18 mai 2005 - 18 mai 2005 à 17:33
Bonjour, je suis debutante en Vb, et je ne comprends pas comment faire pour me connecter à un ftp et prendre un fichier...

Il y aura-t-il une ame charitable qui m'aidera ??
Merci d'avance !

Voila ma source :

Option Explicit
Const FTP_TRANSFER_TYPE_ASCII = &H1
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 FILE_ATTRIBUTE_NORMAL = &H80
Const INTERNET_INVALID_PORT_NUMBER = 21

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 FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal handle As Long, ByVal remotefile As String, ByVal localfile As String, ByVal ifexits As Long, ByVal attributes As Long, ByVal flags As Long, ByVal context 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 Sub Forme()

Dim hopen As Long, hConnection As Long, toto As String, stat As Integer
Const PassiveConnection As Boolean = True
stat = 21

hopen = InternetOpen("API-FTP", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
InternetConnect hopen, "ftp://guideduw:alteance@240Pack.ovh.net/www/BDD/", INTERNET_INVALID_PORT_NUMBER, "guideduw", "alteance", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, &H0

'toto = String(260, 0)

'FtpSetCurrentDirectory hConnection, "//"
'FtpGetCurrentDirectory hConnection, toto, Len(toto)
' fichier sur local nom fichier sur FTP

stat = FtpGetFile(hConnection, "HOTSPOTS.mdb", "\ftp.mdb", False, 0, FTP_TRANSFER_TYPE_ASCII, 0)

MsgBox stat, vbExclamation, "essai"
'close the FTP connection
InternetCloseHandle hConnection

End Sub

2 réponses

cs_miamia Messages postés 3 Date d'inscription jeudi 21 août 2003 Statut Membre Dernière intervention 27 août 2003
27 août 2003 à 10:58
Bonjour à tous !

J'ai vraiment besoin de savoir comment faire, et ça ne marche vraiment pas, je ne sais pas pourquoi, alors s'il vous plâit aidez moi !!!

Merci d'avance :)

miamia

> Voila ma source :
>
> Option Explicit
> Const FTP_TRANSFER_TYPE_ASCII = &H1
> 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 FILE_ATTRIBUTE_NORMAL = &H80
> Const INTERNET_INVALID_PORT_NUMBER = 21
>
> 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 FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal handle As Long, ByVal remotefile As String, ByVal localfile As String, ByVal ifexits As Long, ByVal attributes As Long, ByVal flags As Long, ByVal context 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 Sub Forme()
>
> Dim hopen As Long, hConnection As Long, toto As String, stat As Integer
> Const PassiveConnection As Boolean = True
> stat = 21
>
> hopen = InternetOpen("API-FTP", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
> InternetConnect hopen, "ftp://ftp.guide-du-wifi.com/www/BDD/", INTERNET_INVALID_PORT_NUMBER, "guideduw", "alteance", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, &H0
>
> 'toto = String(260, 0)
>
> 'FtpSetCurrentDirectory hConnection, "//"
> 'FtpGetCurrentDirectory hConnection, toto, Len(toto)
> ' fichier sur local nom fichier sur FTP
>
>
> stat = FtpGetFile(hConnection, "HOTSPOTS.mdb", "\ftp.mdb", False, 0, FTP_TRANSFER_TYPE_ASCII, 0)
>
> MsgBox stat, vbExclamation, "essai"
> 'close the FTP connection
> InternetCloseHandle hConnection
>
> End Sub
0
xmanuxs Messages postés 4 Date d'inscription jeudi 9 septembre 2004 Statut Membre Dernière intervention 18 mai 2005
18 mai 2005 à 17:33
Vous auriez pas un bout de code qui traine pour envoyer un fichier
sur server ftp.
Merci d'avance.
0
Rejoignez-nous