nashoy
Messages postés125Date d'inscriptiondimanche 6 avril 2003StatutMembreDernière intervention 7 octobre 2006
-
8 avril 2004 à 19:11
Hteamspy
Messages postés7Date d'inscriptiondimanche 26 mai 2002StatutMembreDernière intervention27 février 2005
-
11 juin 2004 à 09:20
Salut à tous,
j'ai cherché toutes les sources possibles sur vbfrance, je les ai analysées, et pis bon, j'ai tjs pas vraiment compris comment faire pour envoyer des fichiers. Vu que j'en ai besoin pour un programme que je suis en train de faire, j'ai cherché une source simple (je remercie l'auteur qui se reconaitra ) et j'ai essayé de l'inserer dans ma source.
Mais voila, ça ne marche tjs pas comme voulu...
C'est pk je vous demande a l'aide ... merci
Voila ma source client :
Private Sub Command1_Click()
MyPath = "c:" ' Définit le chemin d'accès.
End Sub
Private Sub Command3_Click()
Dim Ip As String
If Serveur.State <> sckConnected Then
Serveur.Close
Ip = InputBox("Veuillez entrer l'ip du pc distant(ou le nom d'hôte", "NaShOy", "")
Else: MsgBox "Vous êtes déjà connecté", vbExclamation, "NaShOy"
End If
If Ip <> "" Then Serveur.Connect Ip, 5010
End Sub
Private Sub Serveur_DataArrival(ByVal bytesTotal As Long)
Dim msg As String
Serveur.GetData msg
If Left(msg, 6) = "/FILE:" Then
Pos1 = InStr(2, msg, "/")
Fichier = CStr(Mid(msg, 7, Pos1 - 7))
rep = MsgBox("Le serveur essaie de vous envoyer le fichier : " & Fichier & vbCrLf & "Voulez-vous le recevoir ?", vbYesNo + vbQuestion + vbSystemModal, " Transfert de fichier")
If rep = vbYes Then
' Envoi accepté
Temp = CDbl(Right(msg, Len(msg) - Pos1)) ' Taille du fichier dans Temp
Serveur.SendData "/ACCEPT" ' On envoie la réponse au serveur
Else
Serveur.SendData "/REFUSE"
End If
Else
If Num = 0 Then
' Début de l'envoi du fichier
Num = FreeFile ' Numero de fichier libre
Open "c:\fichier.ext" For Binary As #Num
Put #Num, , msg ' Début d'écriture
Else
Put #Num, , msg
End If
Etat = Etat + bytesTotal ' Taille des données reçues
DoEvents
If Etat = Temp Then
Close #Num ' Ferme le fichier
Num = 0
Etat = 0
End If
End If
End Sub
Private Sub TmrEtat_Timer()
Select Case Serveur.State
Case 0
LblEtat.Caption = "Déconnecté"
Case 7
LblEtat.Caption = "Connecté"
Case 4
Serveur.Close
End Select
If Serveur.State <> sckClosed Then
If Serveur.State <> 7 Then Serveur.Close
End If
End Sub
Enfait le client se connecte au serveur, et le serveur renvoi le listage.
Et voici le code serveur :
Private Sub Client_Close()
Client.Close
Client.Listen
End Sub
Private Sub Client_ConnectionRequest(ByVal requestID As Long)
Client.Close
Client.Accept requestID
End Sub
Private Sub Client_DataArrival(ByVal bytesTotal As Long)
' On récupère la réponse envoyé par le serveur dans une variable de
' type String.
Client.GetData msg, vbString
Select Case msg
Case "/REFUSE"
' Réponse -
Case "/ACCEPT"
' Réponse +
Call SendFile
End Select
End Sub
Private Sub Command1_Click()
MyPath = "c:" ' Définit le chemin d'accès.
Charge
'Charge2
End Sub
Private Sub Command3_Click()
For p = Len(txt_file) To 1 Step -1
If Mid(txt_file, p, 1) = "" Then Exit For
Next p
' Syntaxe d'envoi de fichier > "/FILE:NOM_DU_FICHIER/TAILLE
Client.SendData "/FILE:" & Right(txt_file, Len(txt_file) - p) & "/" & FileLen(txt_file)
End Sub
Private Sub Form_Load()
Client.Close
Client.Listen
End Sub
Private Sub List1_DblClick()
Dim Dossier As String
Dossier = List1.List(List1.ListIndex) 'renvoi le txt,tandis que list1.listindex renvoi le num de l'item
If Right$(MyPath, 1) <> "" Then
MyPath = MyPath & ""
End If
MyPath = MyPath & Dossier & ""
List1.Clear
Text1.Text = MyPath 'pour récupérer le contenu de la variable dans Charge2
Charge
Charge2
End Sub
Private Sub TmrListen_Timer()
If Client.State <> 2 Then '2 = scklistening
If Client.State <> sckConnected Then Client.Close: Client.Listen
End If
End Sub
Public Sub Trie()
Dim Pos1, Pos2 As Integer
Dim Index As Integer
Dim Inhalt_List1 As String
Inhalt_List1 = List1.List(0)
Index = 0
Pos1 = InStr(1, Inhalt_List1, "R")
Do
Pos2 = InStr(Pos1 + 1, Inhalt_List1, "R")
' Ausstieg
If Pos2 = 0 Then
List1.List(Index) = Mid(Inhalt_List1, Pos1 + 1, Len(Inhalt_List1) - Pos1)
Exit Do
End If
List1.List(Index) = Mid(Inhalt_List1, Pos1 + 1, Pos2 - Pos1 - 1)
Index = Index + 1
Pos1 = Pos2
Loop
List1.List(0) = Replace(List1.List(0), "R", "")
End Sub
Public Sub Charge2()
Dim Répertoire As String
Dim FichierTrouvé As String
List2.Clear
Répertoire = Text1.Text
FichierTrouvé = Dir(Répertoire & "*.*")
While FichierTrouvé <> ""
Text1.Text = Text1.Text & vbCrLf & FichierTrouvé
FichierTrouvé = Dir()
'client.SendData "F" & FichierTrouvé
Wend
End Sub
Public Sub Charge()
MyPath = "c:"
' Affiche les noms dans C:\ représentant des
' répertoires.
' Extrait la première entrée.
MyName = Dir(MyPath, vbDirectory)
Do While MyName <> "" ' Commence la boucle.
' Ignore le répertoire courant et le répertoire
' contenant le répertoire courant.
If MyName = "." Then
If MyName = ".." Then
MyName = "Retour"
List1.AddItem MyName
End If
Else
' Utilise une comparaison au niveau du bit pour vérifier que MyName est un répertoire.
If (GetAttr(MyPath & "" & MyName) And vbDirectory) = vbDirectory Then
'client.SendData "R" & MyName
' Affiche l'entrée uniquement si elle représente un répertoire.
End If
End If
MyName = Dir ' Extrait l'entrée suivante.
Loop
End Sub
Public Sub SendFile()
' Envoi du fichier
qnr = FreeFile ' Numéro de fichier libre
Open txt_file For Binary As #qnr
' Affichage du statut
Envoie = True
' On découpe le fichier en parties de 100 KO pour accélérer l'envoi du fichier
nb = LOF(qnr) / 100000
If nb <> Int(nb) Then nb = Int(nb) + 1
' On crée une boucle qui envoie les parties de 100 KO au client
For i = 1 To nb
If i <> nb Then
' Préparation du tampon pour les parties de 100 ko
temp$ = Space(100000)
Else
' Préparation du tampon pour le reste du fichier
temp$ = Space(LOF(qnr) - (100000 * (i - 1)))
End If
Get #qnr, , temp$ ' Lecture du fichier dans le tampon
DoEvents ' Rend la main à windows
Client.SendData temp$ ' Envoie les données
Next i
Close #qnr ' Fermeture du fichier
End Sub
Voila ... donc je remercie d'avance les personnes qui auront la bonté de m'aider :kisses) :)
>:) nashoy 8-)
nashoy
Messages postés125Date d'inscriptiondimanche 6 avril 2003StatutMembreDernière intervention 7 octobre 2006 10 juin 2004 à 15:00
Salut Nicolas,
Et bien en fait je vais te donner la source à partir de laquelle je me suis inspiré (encore merci à l'auteur) :
Voilà le lien Bonne chance,
>:) nashoy 8-)