OVH Cloud OVH Cloud

envoie de fichier avec ftp

13 réponses
Avatar
michael
Bonjour, j'essaie d'envoier un fichier txt par ftp averc inet, malgré des
heures de recherches je n'ai trouvé que ceci, il tourne mais ne me donne
aucune erreur mais y a t'il moyen de savoir si tout c bien passé???
J'ai egalement le inet1_statechanged mais il ne rentre pas dedans lors de
'execute"
est ce que le code est correct?? ou y a t'il une erreur??
qqn peut t'il m'aider
d'avance merci

voici mon code:

Private Sub Command2_Click()

With Inet
.AccessType = icUseDefault
.Protocol = icFTP
.UserName = "********************"
.Password = "*******"
Inet.Execute "ftp:\\www.air********.org", "Put", "C:\brussel.txt"
Do Until Not (.StillExecuting)
DoEvents
Loop
End With

MsgBox "Terminé"

End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)

' Purpose: This is to capture the FTP state change i.e exa: once 'FTP is
getting connected.


On Error Resume Next
Dim vtData As Variant
Select Case State
Case icNone
Case icResolvingHost: Me.lblRESPONSE.Caption = "Resolving Host"
Case icHostResolved: Me.lblRESPONSE.Caption = "Host Resolved"
Case icConnecting: Me.lblRESPONSE.Caption = "Connecting..."
Case icConnected: Me.lblRESPONSE.Caption = "Connected"
Case icResponseReceived: Me.lblRESPONSE.Caption = "Transferring File..."
Case icDisconnecting: Me.lblRESPONSE.Caption = "Disconnecting..."
Case icDisconnected: Me.lblRESPONSE.Caption = "Disconnected"
Case icError: MsgBox "Error:" & Inet1.ResponseCode & " " & Inet1.ResponseInfo
Case icResponseCompleted: Me.lblRESPONSE.Caption = "Process Complete."
End Select

Me.lblRESPONSE.Refresh

Err.Clear

End Sub

3 réponses

1 2
Avatar
michael
la version est VB 6.0
sinon j'ai utilisé plusieurs code deja, même certain de msn, ou d'autere
corrigé par les remarque de sites et forum
le premier:
-un seul boutoin de commande:

Private Sub Command2_Click()

With Inet
.AccessType = icUseDefault
.Protocol = icFTP
.UserName = "brusse*******egion"
.Password = "********"
Inet.Execute "ftp:www.*************.org", "Put" & " " &
"C:brussel.txt" & " " & "brussel.txt"
Do Until Not (.StillExecuting)
DoEvents
Loop
End With

MsgBox "Terminé"

End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
Debug.Print State
' Purpose: This is to capture the FTP state change i.e exa: once 'FTP is
getting connected.

On Error Resume Next
Dim vtData As Variant
Select Case State
Case icNone
Case icResolvingHost: Me.lblRESPONSE.Caption = "Resolving Host"
Case icHostResolved: Me.lblRESPONSE.Caption = "Host Resolved"
Case icConnecting: Me.lblRESPONSE.Caption = "Connecting..."
Case icConnected: Me.lblRESPONSE.Caption = "Connected"
Case icResponseReceived: Me.lblRESPONSE.Caption = "Transferring File..."
Case icDisconnecting: Me.lblRESPONSE.Caption = "Disconnecting..."
Case icDisconnected: Me.lblRESPONSE.Caption = "Disconnected"
Case icError: MsgBox "Error:" & Inet1.ResponseCode & " " & Inet1.ResponseInfo
Case icResponseCompleted: Me.lblRESPONSE.Caption = "Process Complete."
End Select

Me.lblRESPONSE.Refresh

Err.Clear

End Sub

-ici il ne veux déja pas rentrer dans l'evenement StateChanged...pq??
mystère...

Le second:
Dim net As Inet
Dim flag As Boolean
Dim State As Integer
Dim AccessType As String

Private Sub cmdbrowse_Click()
CommonDialog1.Filter = "All files(*.*)|*.*|text file(*.txt)|*.txt"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen
Text2.Text = CommonDialog1.fileName
End Sub

Private Sub cmdupload_Click()
Dim localfile As String
Dim remoteFile As String
Dim fileName As String
Dim filepath, fileid As String
Dim seperatorPos, s1 As Integer

ChDir App.Path ' for setting the cwd.
localfile = Text2.Text
seperatorPos = InStrRev(localfile, "", -1, vbTextCompare)
fileName = Right(localfile, Len(localfile) - seperatorPos)
s1 = InStrRev(localfile, "", -1, vbTextCompare)
fileid = Right(localfile, Len(localfile) - s1)
MsgBox fileid
'filepath = fReturnFilePath(fileName, App.Path)
'intDataNum = intDataNum + 1 '... this may be used to mention the successful
uploads
remoteFile = "remote directory name where to store" & fileName
Dim str As String
'Text1.Text = localfile
'str = " " & localFile & " " & remoteFile
'Text1.Text = str
Inet1.Execute , "PUT " & localfile
'Inet1.Execute , "PUT " & localFile & " " & remoteFile & " " '.. Successful
upload bulk commented due to updations
'Inet1.Execute , "PUT ""c:hellmsn.exe"" ""html/snjoshiNew/hellmsn.exe""" '
for Single file upload
Me.lblRESPONSE.Caption = " Response : " & Inet1.ResponseInfo & " Response
Code " & Inet1.ResponseCode
Me.lblRESPONSE.Caption = "Application File Successfully Purged." &
vbExclamation
MsgBox "Application File Successfully Purged.", vbExclamation
End Sub


Private Sub Inet1_StateChanged(ByVal State As Integer)

' Purpose: This is to capture the FTP state change i.e exa: once 'FTP is
getting connected.


On Error Resume Next
Dim vtData As Variant
Select Case State
Case icNone
Case icResolvingHost: Me.lblRESPONSE.Caption = "Resolving Host"
Case icHostResolved: Me.lblRESPONSE.Caption = "Host Resolved"
Case icConnecting: Me.lblRESPONSE.Caption = "Connecting..."
Case icConnected: Me.lblRESPONSE.Caption = "Connected"
Case icResponseReceived: Me.lblRESPONSE.Caption = "Transferring File..."
Case icDisconnecting: Me.lblRESPONSE.Caption = "Disconnecting..."
Case icDisconnected: Me.lblRESPONSE.Caption = "Disconnected"
Case icError: MsgBox "Error:" & Inet1.ResponseCode & " " & Inet1.ResponseInfo
Case icResponseCompleted: Me.lblRESPONSE.Caption = "Process Complete."
End Select

Me.lblRESPONSE.Refresh

Err.Clear

End Sub


La il me met a la fin que le 'file is successfully purged' il ne bug pas,
mais je rentrouve pas le fichier dans le serveur, en fait rien ne c'est
fait...
le stateChanged reste 1 dans ce cas ci...

voila si tu as des idées où ca bug???



"Jacques93" a écrit :

Bonjour michael,
michael a écrit :
> bonjour, je crois qu'il est impossible de faire ca en vb... j'ai tout essaier
> ca fais trois jours, rien, pas la moindre commande ne fonctionne... parfois
> aucune erreur ne se produit mais il se passe rien, soit il y a des erreurs...
> je comprend rien du tout!! ca parait simple comme ca, on donne le mot de
> passe l'add et le username avec inet et hop... mais a mon avis c impossible a
> faire!!
> j'ai verifier avec un client ftp sur le serveur dont j'ai acces, et essaier
> d'effectuer une simple commande, GET PUT ou autre rien n'y fais, j'ai chager
> la syntaxe la faocn d'ecrire tout...
> merci quand même
>

Peux tu publier ton code ici ?
Quelle est ta version VB. MsInet semble buggé sous VB5.

--
Cordialement,

Jacques.



Avatar
Jacques93
Bonjour michael,
michael a écrit :
la version est VB 6.0
sinon j'ai utilisé plusieurs code deja, même certain de msn, ou d'autere
corrigé par les remarque de sites et forum
le premier:
-un seul boutoin de commande:

Private Sub Command2_Click()

With Inet
.AccessType = icUseDefault
.Protocol = icFTP
.UserName = "brusse*******egion"
.Password = "********"
Inet.Execute "ftp:www.*************.org", "Put" & " " &
"C:brussel.txt" & " " & "brussel.txt"
Do Until Not (.StillExecuting)
DoEvents
Loop
End With

MsgBox "Terminé"

End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
Debug.Print State
' Purpose: This is to capture the FTP state change i.e exa: once 'FTP is
getting connected.

On Error Resume Next
Dim vtData As Variant
Select Case State
Case icNone
Case icResolvingHost: Me.lblRESPONSE.Caption = "Resolving Host"
Case icHostResolved: Me.lblRESPONSE.Caption = "Host Resolved"
Case icConnecting: Me.lblRESPONSE.Caption = "Connecting..."
Case icConnected: Me.lblRESPONSE.Caption = "Connected"
Case icResponseReceived: Me.lblRESPONSE.Caption = "Transferring File..."
Case icDisconnecting: Me.lblRESPONSE.Caption = "Disconnecting..."
Case icDisconnected: Me.lblRESPONSE.Caption = "Disconnected"
Case icError: MsgBox "Error:" & Inet1.ResponseCode & " " & Inet1.ResponseInfo
Case icResponseCompleted: Me.lblRESPONSE.Caption = "Process Complete."
End Select

Me.lblRESPONSE.Refresh

Err.Clear

End Sub

-ici il ne veux déja pas rentrer dans l'evenement StateChanged...pq??
mystère...



Dans la procèdure Command2_Click, ton contrôle s'appelle Inet :

With Inet
Inet.Execute

Il est donc normal de ne jamais entrer dans Inet1_StateChanged
D'autre part il serait préférable de renseigner la propriété URL :

Private Sub Command2_Click()
With Inet1
.URL = "ftp://NomDeTonServeurFTP"
.AccessType = icUseDefault
.Protocol = icFTP

.UserName = "TonNom"
.Password = "TonMotDePasse"
Inet1.Execute , "Put" & " " & "C:brussel.txt" & " " _
& "brussel.txt"
Do Until Not (.StillExecuting)
DoEvents
Loop
End With
MsgBox "Terminé"
End Sub

Tu noteras au passage que l'url est de la forme ftp:// et non pas ftp:
Le fait de renseigner la propriété .URL a pour effet de renseigner
.RemoteHost

Par ailleurs je suis étonné que le nom de ton server FTP commence par
www ("ftp:www.*************.org")

Le code ci-dessus (avec .URL, .UserName, .Password correct) fonctionne
correctement.

Je regardel'autre code un peu plus tard ...
--
Cordialement,

Jacques.
Avatar
Jacques93
Bonjour michael,
michael a écrit :

Le second:
Dim net As Inet
Dim flag As Boolean
Dim State As Integer
Dim AccessType As String

Private Sub cmdbrowse_Click()
CommonDialog1.Filter = "All files(*.*)|*.*|text file(*.txt)|*.txt"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen
Text2.Text = CommonDialog1.fileName
End Sub

Private Sub cmdupload_Click()
Dim localfile As String
Dim remoteFile As String
Dim fileName As String
Dim filepath, fileid As String
Dim seperatorPos, s1 As Integer

ChDir App.Path ' for setting the cwd.
localfile = Text2.Text
seperatorPos = InStrRev(localfile, "", -1, vbTextCompare)
fileName = Right(localfile, Len(localfile) - seperatorPos)
s1 = InStrRev(localfile, "", -1, vbTextCompare)
fileid = Right(localfile, Len(localfile) - s1)
MsgBox fileid
'filepath = fReturnFilePath(fileName, App.Path)
'intDataNum = intDataNum + 1 '... this may be used to mention the successful
uploads
remoteFile = "remote directory name where to store" & fileName
Dim str As String
'Text1.Text = localfile
'str = " " & localFile & " " & remoteFile
'Text1.Text = str
Inet1.Execute , "PUT " & localfile
'Inet1.Execute , "PUT " & localFile & " " & remoteFile & " " '.. Successful
upload bulk commented due to updations
'Inet1.Execute , "PUT ""c:hellmsn.exe"" ""html/snjoshiNew/hellmsn.exe""" '
for Single file upload
Me.lblRESPONSE.Caption = " Response : " & Inet1.ResponseInfo & " Response
Code " & Inet1.ResponseCode
Me.lblRESPONSE.Caption = "Application File Successfully Purged." &
vbExclamation
MsgBox "Application File Successfully Purged.", vbExclamation
End Sub



[...]

La il me met a la fin que le 'file is successfully purged' il ne bug pas,
mais je rentrouve pas le fichier dans le serveur, en fait rien ne c'est
fait...
le stateChanged reste 1 dans ce cas ci...

voila si tu as des idées où ca bug???




Ici ni .URL, ni .UserName, ni .Password ne sont renseigné, si ce sont
sont du premier exemple, ils étaient affectés à Inet et non à Inet1, et
le nom du site (ftp: au lieu de ftp://) était incorrect.

D'autre part la syntaxe utilisée ici :

Inet1.Execute , "PUT " & localfile

est incomplète ...

Vraiment pas clair tout ça , ou le code est incomplet ...
En tout cas si le status reste à 1 (icHostResolvingHost), c'est que le
serveur n'est pas trouvé, ou ne réponds pas. De plus tu n'as pas de
boucle d'attente sur StillExecuting ...

Essaie de repartir du code indiqué dans le message précédent.

PS : A quoi sert

Dim net As Inet

Au début de ton code ?

--
Cordialement,

Jacques.
1 2