Bonjour,
J'ai un problème sur un chargement d'un dossier sur un serveur FTP, le fichier excel fait 27Mo en taille, c'est peut être cela qui bloque le transfert. En fait quand j'arrive au transfert, il m'indique que le transfert n'est pas possible dans la msgbox.
J'ai lu et relu plusieurs textes sur l'export FTP mais je ne vois pas d'où vient ce problème. J'ai même vérifier les API et ça colle avec ce que j'ai lu.
Je suis sur excel 2010.
Je vous joint ci-dessous mon code VBA en modifiant les paramètres :
	
	
	
	
	
		
Merci d'avance pour vos retours.
Eideal44
	
		
			
		
		
	
				
			J'ai un problème sur un chargement d'un dossier sur un serveur FTP, le fichier excel fait 27Mo en taille, c'est peut être cela qui bloque le transfert. En fait quand j'arrive au transfert, il m'indique que le transfert n'est pas possible dans la msgbox.
J'ai lu et relu plusieurs textes sur l'export FTP mais je ne vois pas d'où vient ce problème. J'ai même vérifier les API et ça colle avec ce que j'ai lu.
Je suis sur excel 2010.
Je vous joint ci-dessous mon code VBA en modifiant les paramètres :
		Code:
	
	
	Option Explicit
'-------------------
'Déclaration des API
'-------------------
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 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
'************************************************************************************
'************************************************************************************
'transfère des fichiers du disque local vers un serveur ftp (upload, mode passif)
Sub EXPORT_FTP()
Dim CONNEXION As Long
Dim OUVERTURE As Long
Dim SELECTION_DOSSIER
Dim FICHIER
'PARAMETRES : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
IP = "000.00.000.000"
LOG = "testlog"
MDP = "mdp"
FICHIER = "nom-fichier.xls"
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Application.ScreenUpdating = False
On Error GoTo Err_Sub
'ouvre internet
OUVERTURE = InternetOpen("ftp://" & IP", 0, vbNullString, vbNullString, 0)
    If OUVERTURE = 0 Then
        InternetCloseHandle OUVERTURE 'Fermer internet
        Application.Wait Now + TimeValue("00:00:30") 'attendre 30 secondes
        EXPORT_FTP 'relancer la macro
    Else
        'Connection au site ftp
        CONNEXION = InternetConnect(OUVERTURE, IP, 21, LOG, MDP, 1, 0, 0)
            If CONNEXION = 0 Then
                InternetCloseHandle CONNEXION
                InternetCloseHandle OUVERTURE 'Fermer internet
                Application.Wait Now + TimeValue("00:00:30")
                EXPORT_FTP
            Else
            'test si presence du fichier
            SELECTION_DOSSIER = FtpSetCurrentDirectory(CONNEXION, "/import_excel")
                    If SELECTION_DOSSIER = 0 Then
                        InternetCloseHandle CONNEXION
                        InternetCloseHandle OUVERTURE
                        Application.Wait Now + TimeValue("00:00:30")
                        EXPORT_FTP
                    Else
                        TRANSFERT = FtpPutFile(CONNEXION, "TEST", "M:\" & FICHIER, &H2, 0)
                            If TRANSFERT Then
                    
                            MsgBox "ok"
                    
                                InternetCloseHandle CONNEXION
                                InternetCloseHandle OUVERTURE
                    
                            Else
                    
                            MsgBox "n'arrive pas a transferer"
                    
                                InternetCloseHandle CONNEXION
                                InternetCloseHandle OUVERTURE
                                Application.Wait Now + TimeValue("00:05:00")
                                EXPORT_FTP
                            End If
                    End If
            End If
    End If
    
Application.ScreenUpdating = True
    
Exit Sub
Err_Sub:
    InternetCloseHandle CONNEXION
    InternetCloseHandle OUVERTURE
    EXPORT_FTP
    End
End Sub
'************************************************************************************
	Merci d'avance pour vos retours.
Eideal44