Aidez-moi svp je commence!

jnbrunet Messages postés 258 Date d'inscription samedi 25 décembre 2004 Statut Membre Dernière intervention 13 novembre 2012 - 22 janv. 2005 à 06:09
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 - 22 janv. 2005 à 21:58
Bonjours, voici ma question. J'ai trouvé sur ce site une source d'un "file transport" qui utilise winsock. Il est très bien. J'ai un seul petit problème, je voudrais enlevé une de ses fonctions. Lorsque le client envoie un fichier, le serveur demande s'il accepte le fichier et lui demande ou il veut le metre. Moi je veux que dès que le serveur accepte, le fichier va s'enregistrer dans c:\windows\. Est-ce possible? Voiçi la source du serveur:
Option Explicit
Dim Port As Integer
Dim Taille As Double
Dim TailleEnCours As Double


Private Sub Form_Load()

Port = 1024

If ws1.State <> 0 Then ws1.Close
ws1.LocalPort = Port
ws1.Listen
Me.Caption = "Serveur en écoute ..."
End Sub


Private Sub ws1_Close()
Close #1
If ws1.State <> 0 Then ws1.Close
Me.Caption = "ERREUR: Déconnexion de l'emmeteur !"
Text1.Text = ""
Text2.Text = ""
pb1.Value = 0
ws1.LocalPort = Port
ws1.Listen
Me.Caption = "Serveur en écoute ..."
End Sub


Private Sub ws1_ConnectionRequest(ByVal requestID As Long)
Me.Caption = ""
Dim Ret As Integer
Ret = MsgBox("Acceptez-vous le transfert venant de " & ws1.RemoteHostIP & " ?", vbYesNo)
If Ret = vbYes Then
If ws1.State <> 0 Then ws1.Close
ws1.Accept requestID
Me.Caption = "Connexion accepté !"
Else
If ws1.State <> 0 Then ws1.Close
ws1.LocalPort = Port
ws1.Listen
Me.Caption = "Serveur en écoute ..."
End If
End Sub


Private Sub ws1_DataArrival(ByVal bytesTotal As Long)
Dim PB As Integer
Dim Data As String
Dim Commandes As String
ws1.GetData Data
Commandes = Left(Data, 5)
If Len(Data) > 5 Then Data = Right(Data, Len(Data) - 5)
If Commandes = "INFOS" Then
Dim Info() As String
Info() = Split(Data, "|")
Text1.Text = Info(0)
Taille = Val(Info(1))
TailleEnCours = 0
pb1.Min = 0
pb1.Max = 100
pb1.Value = 0
Me.Caption = "Transfert en cours ..."
cd1.Flags = &H4
cd1.Filter = "Tous les fichiers (*.*)|*.*"
cd1.FileName = Text1.Text
cd1.ShowSave
Open cd1.FileName For Binary As #1
DoEvents
ws1.SendData "GO---"
Exit Sub
End If
If Commandes = "PACKS" Then
Put #1, , Data
DoEvents
TailleEnCours = TailleEnCours + Len(Data)
If TailleEnCours > Taille Then TailleEnCours = Taille
PB = Int((TailleEnCours / Taille) * 100)
If PB < 0 Then PB = 0
If PB > 100 Then PB = 100
pb1.Value = PB
Text2.Text = CStr(PB) & "%"
DoEvents
ws1.SendData "SUITE" & CStr(TailleEnCours)
DoEvents
End If
If Commandes = "ENDPK" Then
Put #1, , Data
DoEvents
TailleEnCours = TailleEnCours + Len(Data)
If TailleEnCours > Taille Then TailleEnCours = Taille
PB = Int((TailleEnCours / Taille) * 100)
If PB < 0 Then PB = 0
If PB > 100 Then PB = 100
Text2.Text = CStr(PB) & "%"
pb1.Value = PB
DoEvents
Close #1
If ws1.State <> 0 Then ws1.Close
Me.Caption = ""
MsgBox "[Récepteur]" & vbCrLf & vbCrLf & "Transfert terminé !"
Text1.Text = ""
Text2.Text = ""
pb1.Value = 0
ws1.LocalPort = Port
ws1.Listen
Me.Caption = "Serveur en écoute ..."
End If
End Sub


Private Sub ws1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Close #1
If ws1.State <> 0 Then ws1.Close
Me.Caption = ""
MsgBox "[Récepteur]" & vbCrLf & vbCrLf & "ERREUR: " & Description
Text1.Text = ""
Text2.Text = ""
pb1.Value = 0
ws1.LocalPort = Port
ws1.Listen
Me.Caption = "Serveur en écoute ..."
End Sub

IMPORTANT: Cette source n'est pas de moi mais d'un excellent programmeur qui a ajouté cette excellente source sur ce site! Malheureusement je ne me rapelle pas de son nom!

3 réponses

Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
22 janv. 2005 à 09:00
enlève le CommonDialog et remplace le nom du fichier par un nom valide:

<STRIKE>cd1.Flags = &H4
cd1.Filter = "Tous les fichiers (*.*)|*.*"
cd1.FileName = Text1.Text
cd1.ShowSave</STRIKE>
Open <STRIKE>cd1.FileName</STRIKE> For Binary As #1
remplaçé par:

Open "C:\Windows\TonFichier" For Binary As #1

mais est tu bien sûr que l'utilisateur a toujours installé Windows dans C:\Windows sinon je te conseille plutôt ça:

Open Environ$("Windir") & "" & "NomFichier" For Binary As #1

Daniel
0
jnbrunet Messages postés 258 Date d'inscription samedi 25 décembre 2004 Statut Membre Dernière intervention 13 novembre 2012
22 janv. 2005 à 21:11
Ok super sa marche! mais peux-tu m'expliquer au juste la se que sa veut dire
Open Environ$("Windir") & "" & "NomFichier" For Binary As #1 et la différence avec l'autre?

Jn
0
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
22 janv. 2005 à 21:58
comme je t'ai dis plus haut WIndir (directory où est intallé Windows) n'est pas forcément C:\Windows et ton programme risque alors de se planter
(directory not found)
la deuxième forme est donc meilleure et fera face à cette situation.

Daniel
0
Rejoignez-nous