Je veux tranferer un fichier .txt sur mon micro vers MVS d'IBM en exceutant un programme VBA sous excel 2000. Le tranfert se passe bien, sauf que le transcodage de mon fichier .txt vers IBM se passe mal. J'ai essayé toutes les options possibles dwFlags ( FTP_TRANSFER_TYPE_ASCII
,etc ... ) dans la fonction FtpPutFile mais rien n'y fait. Par exemple, le fichier dr08b.txt contenant "abc 12" est récupéré sur IBM sous le nom KP50.DR08E contenant "/ÂÄ...". Ci-dessous, mon programme VBA. Merci d'avance pour votre aide



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
 
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 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 FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hFile As Long, ByVal localFile As String, ByVal newRemoteFile As String, ByVal dwFlags As Long, ByVal lContext As Long) As Boolean
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Declare Function FtpOpenFile Lib "wininet.dll" Alias "FtpOpenFileA" (ByVal hFtpSession As Long, ByVal sBuff As String, ByVal Access As Long, ByVal Flags As Long, ByVal Context As Long) As Long
Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
 
Private Sub macro1()
 
Dim HwndConnect As Long
Dim HwndOpen As Long
Dim gt As String
Dim bRet As Boolean
Dim bRep As Boolean
 
 
 
'Ouvre internet
HwndOpen = InternetOpen("PutFtpFile", 1, "", "", 0)
 
gt = HwndOpen
If HwndOpen = 0 Then
        MsgBox "connection internet impossible : " + gt
        Exit Sub
    End If
 
 
'Connection au site ftp - On suppose que le n° de port est 21
HwndConnect = InternetConnect(HwndOpen, "adresse site IBM", 21, _
   "user", "mdp", 1, 0, 0)
   If HwndConnect = 0 Then
        MsgBox "connection  impossible"
        Exit Sub
    End If
 
 
'positionnement du curseur dans le répertoire
If FtpSetCurrentDirectory(HwndConnect, "'KP50.'") = 0 Then
        MsgBox "impossible de trouver le répertoire distant "
        Exit Sub
    End If
 
 
'Envoi du fichier
bRet = FtpPutFile(HwndConnect, "D:\user\dr08b.txt", "DR08E", FTP_TRANSFERT_TYPE_ASCII, 0)
    If bRet Then
        MsgBox " D:\user\dr08b.txt a été transféré "
    Else
        MsgBox "D:\user\dr08b.txt n'a pas pu être transféré"
    End If
 
 
InternetCloseHandle HwndConnect 'Ferme la connection
InternetCloseHandle HwndOpen 'Ferme internet
 
End Sub