Advertisement
Guest User

FTP vb.net

a guest
Jul 8th, 2019
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.09 KB | None | 0 0
  1. Imports System.IO
  2.  
  3. Public Class Form1
  4.     Private FTPDownloader As New Utilities.FTP.FTPclient
  5.  
  6.     'Avvio il programma e setto i campi "Username", "Password", "IP Server"
  7.  
  8.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  9.         TextBox2.Text = "Gianfranco"
  10.         TextBox3.Text = "**************"
  11.         TextBox4.Text = "**************"
  12.     End Sub
  13.  
  14.  
  15.     ' Premendo il tasto "Connetti" o Button1, avvio la connessione FTP in attesa venga accettata dal server
  16.  
  17.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  18.         Try
  19.             FTPDownloader.Hostname = TextBox4.Text.Trim
  20.             FTPDownloader.Username = TextBox2.Text
  21.             FTPDownloader.Password = TextBox3.Text
  22.         Catch ex As Exception
  23.             MessageBox.Show(ex.Message)
  24.         End Try
  25.     End Sub
  26.  
  27.  
  28.  
  29.     'Mostro a schermo i file contenuti all'interno della directory indicata
  30.  
  31.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  32.         FTPDownloader.CurrentDirectory = "/Concerti"
  33.         RefreshList()
  34.     End Sub
  35.  
  36.     Private Sub RefreshList()
  37.         ListBox1.Items.Clear()
  38.         Try
  39.             For Each file In FTPDownloader.ListDirectoryDetail()
  40.                 ListBox1.Items.Add(file.Filename)
  41.             Next
  42.         Catch ex As Exception
  43.             MessageBox.Show(ex.Message)
  44.         End Try
  45.     End Sub
  46.  
  47.  
  48.     'Avvio il download del file interessato...qui avviene l'errore misterioso
  49.  
  50.     Private Sub ListBox1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles ListBox1.MouseDoubleClick
  51.         Try
  52.             If MessageBox.Show("Sei sicuro di voler scaricare il download selezionato? " & ListBox1.SelectedItem, "Conferma", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.OK Then
  53.                 FTPDownloader.Download(ListBox1.SelectedItem, My.Computer.FileSystem.SpecialDirectories.Desktop + "\" + ListBox1.SelectedItem)
  54.             End If
  55.         Catch ex As Exception
  56.             MessageBox.Show(ex.Message)
  57.         End Try
  58.     End Sub
  59. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement