Skip to main content
adicionou 2426 caracteres ao conteúdo
Fonte Link
iuristona
  • 3,9mil
  • 1
  • 16
  • 27

Sua classe não se chama FTP deve possuir um construtor parecido com isso, mas FTPServ, fiz umas modificações:

Public Class FTPFTPServ
    Dim URIFTP As String = ""
    Dim SWServidor As WebRequest = FtpWebRequest.Create(URIFTP)

    Private servidor_Host As String
    Private usuario_Password As String
    Private senha_User As String

    'construtorPublic Property HostnameP As String

        Get
            Return _Host
        End Get
        Set(ByVal V As String)

        End Set
    End Property

    Public Property UsuárioP As String

        Get
            Return _Host
        End Get
        Set(ByVal V As String)

        End Set
    End Property

    Public Property SenhaP As String

        Get
            Return _Password
        End Get
        Set(ByVal V As String)

        End Set
    End Property

    Public Sub New(servidorByVal usuario As String, usuarioByVal senha As String, senhaByVal domain As String)
        Me.servidor_Host = servidordomain
        Me._Password = senha
        Me._User = usuario
    End Sub


    Public Sub UploadFile(ByVal URLArquivo As String, Destino As String)
        ' SWServidor.Credentials = New NetworkCredential(Hostname, Usuário, Senha)
        SWServidor.Method = WebRequestMethods.Ftp.UploadFile
        Try

            Dim ByteFile() As Byte = System.IO.File.ReadAllBytes(Destino)
            Dim MyStream As System.IO.Stream = SWServidor.GetRequestStream()
            MyStream.Write(ByteFile, 0, ByteFile.Length)
            MyStream.Close()
            MyStream.Dispose()

        Catch ex As Exception

            MsgBox("Erro")

        End Try
    End Sub
End Class

    Public Sub New(ByVal usuario As String, ByVal senha As String, ByVal domain As String)
        Me.senha_Host = domain
        Me._Password = senha
        Me._User = usuario
    End Sub


    Public Sub UploadFile(ByVal URLArquivo As String, Destino As String)
        ' SWServidor.Credentials = New NetworkCredential(Hostname, Usuário, Senha)
        SWServidor.Method = WebRequestMethods.Ftp.UploadFile
        Try

            Dim ByteFile() As Byte = System.IO.File.ReadAllBytes(Destino)
            Dim MyStream As System.IO.Stream = SWServidor.GetRequestStream()
            MyStream.Write(ByteFile, 0, ByteFile.Length)
            MyStream.Close()
            MyStream.Dispose()

        Catch ex As Exception

            MsgBox("Erro")

        End Try
    End Sub
End Class

Você declara assim:

Dim ftp As New FTPServ("Servidor", "Usuário" , "Senha")

Sua classe FTP deve possuir um construtor parecido com isso:

Public Class FTP
    Private servidor As String
    Private usuario As String
    Private senha As String

    'construtor
    Public Sub New(servidor As String, usuario As String, senha As String)
        Me.servidor = servidor
        Me.usuario = usuario
        Me.senha = senha
    End Sub
End Class

Sua classe não se chama FTP, mas FTPServ, fiz umas modificações:

Public Class FTPServ
    Dim URIFTP As String = ""
    Dim SWServidor As WebRequest = FtpWebRequest.Create(URIFTP)

    Private _Host As String
    Private _Password As String
    Private _User As String

    Public Property HostnameP As String

        Get
            Return _Host
        End Get
        Set(ByVal V As String)

        End Set
    End Property

    Public Property UsuárioP As String

        Get
            Return _Host
        End Get
        Set(ByVal V As String)

        End Set
    End Property

    Public Property SenhaP As String

        Get
            Return _Password
        End Get
        Set(ByVal V As String)

        End Set
    End Property

    Public Sub New(ByVal usuario As String, ByVal senha As String, ByVal domain As String)
        Me._Host = domain
        Me._Password = senha
        Me._User = usuario
    End Sub


    Public Sub UploadFile(ByVal URLArquivo As String, Destino As String)
        ' SWServidor.Credentials = New NetworkCredential(Hostname, Usuário, Senha)
        SWServidor.Method = WebRequestMethods.Ftp.UploadFile
        Try

            Dim ByteFile() As Byte = System.IO.File.ReadAllBytes(Destino)
            Dim MyStream As System.IO.Stream = SWServidor.GetRequestStream()
            MyStream.Write(ByteFile, 0, ByteFile.Length)
            MyStream.Close()
            MyStream.Dispose()

        Catch ex As Exception

            MsgBox("Erro")

        End Try
    End Sub
End Class

    Public Sub New(ByVal usuario As String, ByVal senha As String, ByVal domain As String)
        Me._Host = domain
        Me._Password = senha
        Me._User = usuario
    End Sub


    Public Sub UploadFile(ByVal URLArquivo As String, Destino As String)
        ' SWServidor.Credentials = New NetworkCredential(Hostname, Usuário, Senha)
        SWServidor.Method = WebRequestMethods.Ftp.UploadFile
        Try

            Dim ByteFile() As Byte = System.IO.File.ReadAllBytes(Destino)
            Dim MyStream As System.IO.Stream = SWServidor.GetRequestStream()
            MyStream.Write(ByteFile, 0, ByteFile.Length)
            MyStream.Close()
            MyStream.Dispose()

        Catch ex As Exception

            MsgBox("Erro")

        End Try
    End Sub
End Class

Você declara assim:

Dim ftp As New FTPServ("Servidor", "Usuário" , "Senha")
Fonte Link
iuristona
  • 3,9mil
  • 1
  • 16
  • 27

Sua classe FTP deve possuir um construtor parecido com isso:

Public Class FTP
    Private servidor As String
    Private usuario As String
    Private senha As String

    'construtor
    Public Sub New(servidor As String, usuario As String, senha As String)
        Me.servidor = servidor
        Me.usuario = usuario
        Me.senha = senha
    End Sub
End Class