Bonjour, j'essaye d'uploader un fichier sur un ftp en utilisant l'API Wininet.

Je n'ai pas de probleme pour me connecter, ni pour verifier l'existence d'un repertoire(j'ai fait des test et si par exemple un dossier n'existe pas je recoi false et inversement) donc je n'ai pas de probleme de connection.


Par contre pour toutes action de création je recoi une erreur..je ne comprends pas ppourquoi, je vous montre mon code

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" ( _
                        ByVal sAgent As String, ByVal lAccessType As Integer, _
                        ByVal sProxyName As String, _
                        ByVal sProxyBypass As String, ByVal lFlags As Integer) As Integer
 
    Public Declare Function InternetConnect Lib "wininet.dll" _
                        Alias "InternetConnectA" ( _
                        ByVal hInternetSession As Integer, ByVal sServerName As String, _
                        ByVal nServerPort As Integer, ByVal sUsername As String, _
                        ByVal sPassword As String, ByVal lService As Integer, _
                        ByVal lFlags As Integer, ByVal lContext As Integer) As Integer
 
    Public Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias _
                        "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Integer, _
                        ByVal lpszDirectory As String) As Boolean
 
    Public Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" ( _
                        ByVal hFtpSession As Integer, ByVal lpszLocalFile As String, _
                        ByVal lpszRemoteFile As String, _
                        ByVal dwFlags As Integer, ByVal dwContext As Integer) As Boolean
 
    Public Declare Function InternetCloseHandle Lib "wininet.dll" ( _
                        ByVal hInet As Integer) As Integer
 
    Public Declare Function FtpCreateDirectory Lib "wininet.dll" _
            Alias "FtpCreateDirectoryA" ( _
            ByRef hConnect As Integer, _
            ByVal lpszDirectory As String) As Boolean
 
 
    Public Const INTERNET_DEFAULT_FTP_PORT = 21
    Public Const INTERNET_SERVICE_FTP = 1
 
    Public Enum eTRANSFERT_TYPE
        FTP_TRANSFER_TYPE_ASCII = &H1
        FTP_TRANSFER_TYPE_BINARY = &H2
    End Enum
 
    Private Function PutFtpFile(ByVal stRepFtp As String, ByVal stFicFtp As String, _
    ByVal stFicLocal As String) As Boolean
        ' Cette fonction charge un fichier local sur un serveur FTP.
        ' stServ contient le nom ou l'adresse IP du serveur FTP
        ' stLogin est le login à utiliser
        ' stPass est le mot de passe associé au login
        ' stRepFtp est le répertoire FTP ou sera placé le fichier ("/" pour la racine)
        ' stFicFtp est le nom qui sera donné au fichier sur le serveur
        ' stFicLocal est le chemin complet (+nom) du fichier local
        ' lgType est le type de transfert à utiliser (texte ou binaire)
        ' La fonction retourne Vrai si le transfert à réussi, sinon Faux.
        Dim lgFtp As Integer, lgSession As Integer, lgDir As Integer
        Dim inRes As Integer
        Dim blOk As Boolean
        blOk = False
        Dim stServ As String, stLogin As String, stPass As String
 
        stServ = "ftp.*******.fr"
        stLogin = "**********@**********.fr"
        stPass = "********"
 
        ' Récupère un pointeur vers la connexion internet courante
        lgSession = InternetOpen("PutFtpFile", 1, vbNullString, vbNullString, 0)
        If lgSession Then
            ' Récupère un pointeur vers pour session FTP
            lgFtp = InternetConnect(lgSession, stServ, INTERNET_DEFAULT_FTP_PORT, _
                                    stLogin, stPass, INTERNET_SERVICE_FTP, 0, 0)
            If lgFtp Then
                ' Positionne le répertoire distant
                Debug.Print("1")
                If FtpSetCurrentDirectory(lgFtp, stRepFtp) Then
                    Debug.Print("2")
                    ' Envoie le fichier
                    blOk = FtpCreateDirectory(lgFtp, "/test/")
                    'blOk = FtpPutFile(lgFtp, stFicLocal, stFicFtp, &H1, 0)
                End If
            End If
            ' Libération du pointeur
            inRes = InternetCloseHandle(lgFtp)
        End If
        ' Retourne le résultat
        PutFtpFile = blOk
    End Function



Les deux fonctions suivantes ne marchent pas


FtpCreateDirectory(lgFtp, "/test/")
FtpPutFile(lgFtp, stFicLocal, stFicFtp, &H1, 0)


Si quelqu'un sait pourquoi??? est ce que c'est possible en .net tout simplement??