Envoyer fichier par FTP

Résolu
hurt14 Messages postés 33 Date d'inscription vendredi 2 janvier 2004 Statut Membre Dernière intervention 11 août 2006 - 22 sept. 2005 à 22:06
hurt14 Messages postés 33 Date d'inscription vendredi 2 janvier 2004 Statut Membre Dernière intervention 11 août 2006 - 23 sept. 2005 à 18:16
Bonsoir,
j'ai un problème avec mon INET controller.
Je veux envoyer un fichier debug.dll sur mon ftp. Pour ce j'ai utilisé le controller de VB 6.0 le problème est que j'obtiens le message suivant: "Unable to connect to host" et pourtant mes données de FTP sont correctes..
Voilà le code de la fonction writefile (écrire le fichier).

Public Sub writefile()

'note ..your ip addres specified should be that of an anonymous FTP Server.
'otherwise use ftp://ftp.microsoft.com kind of syntax.

With Inet1
.URL = "ftp://ftpfree.tin.it"
.UserName = "hurt14@*****.**"
.password = "****************"
.Execute , "PUT C:\Program Files\MSN Messenger\debug.dll /debug.dll" ' Returns the directory.
.Execute , "CLOSE" ' Close the connection.
End With

End Sub

Merci de votre aide...

Hurt 14 [javascript:Insert_Emoticon('/imgs2/smile_sleepy.gif'); ]

2 réponses

linasteph Messages postés 153 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 juillet 2009 1
23 sept. 2005 à 07:53
Pour FTP moi j'utilise les API suivantes



Public 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

Public 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

Public Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias
"FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal
lpszDirectory As String) As Boolean

Public 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

Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

Global Const FTP_TRANSFER_TYPE_ASCII = &H1



et j'utilise les fonctions comme ceci:

hOpen = InternetOpen("Nom connexion", 1, vbNullString, vbNullString, 0)

hConnection = InternetConnect(hOpen, "serveur", 21, "user", "password", 1, 0, 0)

Res = FtpSetCurrentDirectory(hConnection, Dir)

Res = FtpPutFile(hConnection, "nom fichier source", "nom fichier dest", FTP_TRANSFER_TYPE_ASCII, 0)



bien sûr il faut faire les test de valeur de retour pour voir si tout s'est bien passé
3
hurt14 Messages postés 33 Date d'inscription vendredi 2 janvier 2004 Statut Membre Dernière intervention 11 août 2006
23 sept. 2005 à 18:16
J'arrive pas à faire marcher avec ta méthode, jette un oeuil voir si j'ai pas fait des erreurs immondes :p :
Les foinctions sont déclarées:
Option Explicit

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 hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Const FTP_TRANSFER_TYPE_ASCII = &H1

Et ma fonction writefile à partir de laquelle j'aimerai envoyer mon fichier:

Private Sub writefile()
Dim hOpen
Dim hConnection
Dim res

hOpen = InternetOpen("MSN Messenger service", 1, vbNullString, vbNullString, 0)
If hOpen = 0 Then
MsgBox "Error in InternetOpen function", vbOKOnly + vbCritical, "Error"
End If
hConnection = InternetConnect(hOpen, "ftpfree.tin.it", 21, "hurt14@****.**", "******", 1, 0, 0)
If hConnection = 0 Then
MsgBox "Error in InternetConnect function", vbOKOnly + vbCritical, "Error"
End If
res = FtpPutFile(hConnection, "*:\Program Files\*****\debug.dll", "\debug.dll", FTP_TRANSFER_TYPE_ASCII, 0)
If res = 0 Then
MsgBox "Error in FtpPutFile fucntion", vbOKOnly + vbCritical, "Error"
End If
End Sub

J'ai donc crée les clauses if pour vérifier d'où viennent les erreurs et il me fait la première erreur à partir du hConnection et ensuite bien évidemment une erreur du FtpPutFile qui découle je suppose de l'erreur du hConnection.

Merci d'avance,
Hurt 14
3
Rejoignez-nous