Я возвращаюсь к вам, потому что у меня все еще есть проблема с исходным кодом, я напомню вам, что я пытаюсь выполнить синхронизацию FTP из следующего источника, который я скопировал
Видео: https://www.youtube.com/watch?v=E5qSxrbrf9I
Ошибка:
BC31143 Методы приватного подпапки File_Downloaded (отправитель как объект, как AsyncCompletedEventArgs), совместимая с подписью делегированная подпрограмма делегата DownloadProgressChangedEventHandler (отправитель как объект, e как DownloadProgressChangedEventArgs) '.Ошибка BC30311 Невозможно преобразовать тип 'FtpWebResponse' в 'FtpWebRequest'.Erreur BC30456 'GetResponseStream' не проходит через 'FtpWebRequest'.
FTPManager.vb (класс)
Public Class FTPManager
Private Shared ConfigFile As String =
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) & "\config.txt"
Public Shared Folder As String = "Client_Pokemonia"
Public Shared ServerRootPatch As String
Public Shared User As String
Public Shared PW As String
Public Shared Sub loadConfig()
If IO.File.Exists(ConfigFile) Then
Dim lines = IO.File.ReadAllLines(ConfigFile)
ServerRootPatch = lines(0)
User = lines(1)
PW = lines(2)
End If
End Sub
End Class
Form1.vb
Imports System.ComponentModel
Imports System.Net
Public Class Form1
Private LocalPath As String = "Downloadedfiles"
Private missingFiles As New List(Of String)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FTPManager.loadConfig()
createLocalFolderIfNotExistes()
btnRefresh.performClick()
End Sub
Private Sub createLocalFolderIfNotExistes()
If Not IO.Directory.Exists(LocalPath) Then IO.Directory.CreateDirectory(LocalPath)
End Sub
Private Sub getLocalFiles()
dgvLocal.Rows.clear
Dim files = IO.Directory.GetFiles(LocalPath)
If files.Count > 0 Then
For Each f In files
Me.dgvLocal.Rows.Add(f.Split("\c").Last())
Next
End If
End Sub
Private Sub getFTPFiles()
dgvFTP.Rows.Clear()
missingFiles.Clear()
Dim request = FtpWebRequest.Create(FTPManager.ServerRootPatch)
request.Method = WebRequestMethods.Ftp.ListDirectory
request.Credentials = New NetworkCredential(FTPManager.User, FTPManager.PW)
Dim response As FtpWebRequest = CType(request.GetResponse(), FtpWebResponse)
Using myReader As New IO.StreamReader(response.GetResponseStream())
Do Until Not myReader.EndOfStream
Dim file = myReader.ReadLine()
Me.dgvFTP.Rows.Add(file)
If Not IO.File.Exists(LocalPath & "\" & file) Then
dgvFTP.Rows(dgvFTP.Rows.Count - 1).defaultCellStyle.BackColor = Color.FromArgb(255, 192, 192)
missingFiles.Add(file)
Else : dgvFTP.Rows(dgvFTP.Rows.Count - 1).DefaultCellStyle.BackColor = Color.FromArgb(192, 255, 192)
End If
Loop
End Using
End Sub
Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
' If Not btnRefresh Then
' btnRefresh.Enabled = False
' Await Task.Delay(2000)
' getLocalFiles()
' getFTPFiles()
' btnSync.Enabled = True
' Else : MessageBox.Show("please wait")
' End If
dgvFTP.ClearSelection()
dgvLocal.ClearSelection()
End Sub
Private Sub btnSync_Click(sender As Object, e As EventArgs) Handles btnSync.Click
If missingFiles.Count > 0 Then
Donwload_File(New Uri(FTPManager.ServerRootPatch & FTPManager.Folder & "/" & missingFiles(0)))
Else : MessageBox.Show("No files to downlaod")
End If
End Sub
Private Sub Donwload_File(URI As Uri)
Dim filename = URI.ToString().Split("/c").Last()
prgb.Value = 0
'lblFile.text = filename
Using wc As New WebClient
wc.Credentials = New NetworkCredential(FTPManager.User, FTPManager.PW)
AddHandler wc.DownloadProgressChanged, AddressOf File_DLProgressChanged
AddHandler wc.DownloadProgressChanged, AddressOf File_Downloaded
wc.DownloadFileAsync(URI, LocalPath & "\" & filename)
End Using
End Sub
Private Sub File_DLProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs)
prgb.Value = e.ProgressPercentage
End Sub
Private Sub File_Downloaded(sender As Object, e As AsyncCompletedEventArgs)
Dim deletedFile = missingFiles(0)
missingFiles.RemoveAt(0)
If missingFiles.Count > 0 Then
Donwload_File(New Uri(FTPManager.ServerRootPatch & FTPManager.Folder & "/" & missingFiles(0)))
Else
btnRefresh.PerformClick()
MessageBox.Show("niquel")
End If
End Sub
End Class