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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| Sub upload
Timer1.Enabled = False
Dim yaspc As Boolean
Dim taille As Variant
Dim pourcent As Integer
Dim fic_source, fic_destination As String
yaspc = False
fic_source = dir.Dir1.Path & "/" & dir.File1.FileName 'fichier a uploader"
fic_destination = dir.File1.FileName 'fichier de destination"
'verif fichier pas spc
Dim tmp, tmp2 As String
tmp = dir.File1.FileName
Dim i As Integer
For i = 1 To Len(tmp)
If Mid(tmp, i, 1) = Chr(32) Then
yaspc = True: tmp2 = tmp2 & "_"
Else: tmp2 = tmp2 & Mid(tmp, i, 1)
End If
Next i
'verif si path a spc
tmp = dir.Dir1.Path
For i = 1 To Len(tmp)
If Mid(tmp, i, 1) = Chr(32) Then
yaspc = True
End If
Next i
'si y a spc alors on passe par un temporaire sur c:
If yaspc = True Then
Label1 = "copie du fichier temporaire..."
FileCopy fic_source, "c:\" & tmp2
fic_source = "c:\" & tmp2
fic_destination = tmp2
End If
pb.Min = 0
pb.Max = FileLen(fic_source)
With Inet1
.Protocol = icFTP 'declaration protocole
.URL = dir.Inet1.URL
End With
Inet1.Execute , "put " & fic_source & " " & dir.Label1 & "/" & fic_destination 'envoie du fichier
Inet2.URL = Inet1.URL 'initialise inet2 : mm url
Do Until Inet1.StillExecuting = False 'boucle pendant le traitement de inet1
On Error Resume Next
If Inet2.StillExecuting = False Then 'si inet2 n'est pas actif
Inet2.Execute , "size /" & fic_destination 'demande la taille du fichier sur le ftp
Do Until Inet2.StillExecuting = False 'boucle pendant le demande inet2
DoEvents
Loop
taille = Inet2.GetChunk(1024) 'recuperation du size dans taille
Do Until Inet2.StillExecuting = False 'boucle pendant le demande inet2
DoEvents
Loop
'affichage de la progressbar
pb.Value = taille 'affichage de l'avancement de pb
pourcent = (pb.Value / pb.Max) * 100 'calcul du pourcentage reçu
Label1.Caption = pourcent & "%" 'affichage du % du telechargement
sb.Panels(1).Text = taille & "ko de " & (FileLen(fic_source))
End If
Loop
'si scp effacement du fichier temporaire
If yaspc = True Then
Label1 = "Suppression du fichier temporaire...": Kill "c:\" & tmp2
End If
dir.AfficheList1
Unload Me
End Sub |
Partager