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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| Private Sub LancerDL()
While ListView2.Items.Count > 0
If OldPath <> "" Then FTP.GetCurrentRemoteDir()
If Button1.Text = "Lancer !" Then
Abort = False
Button1.Text = "Annuler !"
ListView2.Enabled = False
For Each item As ListViewItem In ListView2.Items
If item.StateImageIndex = 3 Then
If Microsoft.VisualBasic.Right(item.Text, 4) = ".flv" Then
Dim fichier() = Split(item.SubItems(1).Text, "\")
If Not Directory.Exists(Replace(item.SubItems(1).Text, fichier(fichier.Length - 1), "")) Then
Directory.CreateDirectory(Replace(item.SubItems(1).Text, fichier(fichier.Length - 1), ""))
End If
Success = FTP.AsyncGetFileStart(item.SubItems(0).Text, item.SubItems(1).Text)
If (Not Success) Then
MessageBox.Show(FTP.LastErrorText)
Exit Sub
End If
ProgressBar1.Maximum = Replace(item.SubItems(2).Text, " Mo", "") * 1048576
While Not FTP.AsyncFinished
System.Threading.Thread.Sleep(100)
Application.DoEvents()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' /!\ ERREUR ICI /!\ Index 3 Invalide Si précédemment c'est une boucle While''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
item.SubItems(3).Text = FormatNumber(FTP.DownloadRate / 1024, 2) & " Kb/s" '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ProgressBar1.Value = FormatNumber(FTP.AsyncBytesReceived / 1048576, 2) * 1048576
If Abort Then
FTP.AsyncAbort()
ListView2.Enabled = True
FTP.ChangeRemoteDir(OldPath)
OldPath = ""
Exit Sub
End If
End While
If Not FTP.AsyncSuccess Then
MessageBox.Show(FTP.AsyncLog)
End If
item.Remove()
ProgressBar1.Value = 0
Else
Dim n As Long
If Not Directory.Exists(item.SubItems(1).Text) Then
Directory.CreateDirectory(item.SubItems(1).Text)
End If
FTP.ChangeRemoteDir(item.SubItems(0).Text)
n = FTP.NumFilesAndDirs
If (n < 0) Then
EcrireLog(RichTextBox1, FTP.LastErrorText, Color.Red)
Exit Sub
End If
EcrireLog(RichTextBox1, "Chargement de la liste des dossiers...", Color.Green)
If (n > 0) Then
For i = 0 To n - 1
If (FTP.GetIsDirectory(i) = True) Then
Dim items As String() = New String(2) {}
items(0) = "D:\tmp" & Replace(FTP.GetCurrentRemoteDir(), "/", "\") & "\" & FTP.GetFilename(i)
items(1) = ""
ListView2.Items.Insert(0, FTP.GetCurrentRemoteDir() & "/" & FTP.GetFilename(i), 1).SubItems.AddRange(items)
ListView2.Items(0).StateImageIndex = 3
Else
Dim items As String() = New String(2) {}
items(0) = "D:\tmp" & Replace(FTP.GetCurrentRemoteDir(), "/", "\") & "\" & FTP.GetFilename(i)
items(1) = ConvertFileSize(FTP.GetSize(i))
ListView2.Items.Insert(0, FTP.GetCurrentRemoteDir() & "/" & FTP.GetFilename(i), 2).SubItems.AddRange(items)
ListView2.Items(0).StateImageIndex = 3
End If
Next
item.Remove()
End If
End If
End If
Next
FTP.ChangeRemoteDir(OldPath)
OldPath = ""
ListView2.Enabled = True
Button1.Text = "Lancer !"
Else
Dim reponse = MessageBox.Show("Etes-vous sûr de vouloir annuler les téléchargements et uploads en cours ?", "Annuler", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
Select Case reponse
Case Windows.Forms.DialogResult.Yes
Abort = True
End Select
End If
End While
Button1.Text = "Lancer !"
End Sub |
Partager