Imports System.Net
Imports System.IO
Public Class Form1
    Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
        Dim request As Net.FtpWebRequest = CType(Net.WebRequest.Create(tbHost.Text + tbNewDir.Text), Net.FtpWebRequest)
        request.Credentials = New Net.NetworkCredential(tbUser.Text, tbPass.Text)
        request.Method = Net.WebRequestMethods.Ftp.MakeDirectory
        Dim responce As Net.FtpWebResponse = CType(request.GetResponse(), Net.FtpWebResponse)
        MsgBox("Каталог " & tbNewDir.Text & " создан!")
    End Sub
    Private Sub btnDelDir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelDir.Click
        Dim request As Net.FtpWebRequest = CType(Net.WebRequest.Create(tbHost.Text + tbDelDir.Text), Net.FtpWebRequest)
        request.Credentials = New Net.NetworkCredential(tbUser.Text, tbPass.Text)
        request.Method = Net.WebRequestMethods.Ftp.RemoveDirectory
        Dim responce As Net.FtpWebResponse = CType(request.GetResponse(), Net.FtpWebResponse)
        MsgBox("Каталог " & tbDelDir.Text & " удален!")
    End Sub
    Private Sub btnDelFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelFile.Click
        Dim request As Net.FtpWebRequest = CType(Net.WebRequest.Create(tbHost.Text + tbDelFile.Text), Net.FtpWebRequest)
        request.Credentials = New Net.NetworkCredential(tbUser.Text, tbPass.Text)
        request.Method = Net.WebRequestMethods.Ftp.DeleteFile
        Dim responce As Net.FtpWebResponse = CType(request.GetResponse(), Net.FtpWebResponse)
        MsgBox("Файл " & tbDelFile.Text & " удален!")
    End Sub
    Private Sub btnLeng_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeng.Click
        Dim request As Net.FtpWebRequest = CType(Net.WebRequest.Create(tbHost.Text + tbFileLeng.Text), Net.FtpWebRequest)
        request.Credentials = New Net.NetworkCredential(tbUser.Text, tbPass.Text)
        request.Method = Net.WebRequestMethods.Ftp.GetFileSize
        Dim responce As Net.FtpWebResponse = CType(request.GetResponse(), Net.FtpWebResponse)
        MsgBox(responce.ContentLength / 1024 & " Кб")
    End Sub
    Dim down As New OpenFileDialog
    Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        down.Filter = "Все файлы|*.*|png files|*.png|jpg files|*.jpg|gif files|*.gif|bmp files|*.bmp|exe files|*.exe|rar files|*.rar|zip files|*.zip|txt files|*.txt"
        down.FilterIndex = 1
        If down.ShowDialog = Windows.Forms.DialogResult.OK Then
            TextBox10.Text = down.FileName
            Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(tbHost.Text + tbUpload.Text & down.SafeFileName), System.Net.FtpWebRequest)
            request.Credentials = New System.Net.NetworkCredential(tbUser.Text, tbPass.Text)
            request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
            Dim file() As Byte = System.IO.File.ReadAllBytes(TextBox10.Text)
            Dim strz As System.IO.Stream = request.GetRequestStream()
            strz.Write(file, 0, file.Length)
            strz.Close()
            strz.Dispose()
            MsgBox(down.SafeFileName & " загрузился!")
        Else
            MsgBox("Файл не загружен")
        End If
    End Sub
    Private Sub btnCoonect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
        FaDList.Items.Clear()
        Dim arr() As String
        Dim request As Net.FtpWebRequest = Net.WebRequest.Create(tbHost.Text)
        request.Credentials = New Net.NetworkCredential(tbUser.Text, tbPass.Text)
        request.Method = Net.WebRequestMethods.Ftp.ListDirectoryDetails
        Dim response As Net.FtpWebResponse = request.GetResponse()
        Dim responseStream As Stream = response.GetResponseStream()
        Dim reader As StreamReader = New StreamReader(responseStream)
        Dim lol As String
        Do
            lol = reader.ReadLine
            If Len(lol) < 3 Then Exit Do
            arr = Split(lol, vbNewLine)
            Dim T As String = ""
            For i = 0 To UBound(arr)
                If Len(arr(i)) > 3 Then
                    T = arr(i)
                    FaDList.Items.Add(T.Substring(56, (arr(i).Length - 56)))
                End If
            Next
        Loop
        MsgBox(response.WelcomeMessage)
        reader.Close()
        response.Close()
    End Sub
End Class