diff --git a/My Project/Application.Designer.vb b/My Project/Application.Designer.vb
new file mode 100644
index 0000000..24aaa49
--- /dev/null
+++ b/My Project/Application.Designer.vb
@@ -0,0 +1,13 @@
+'------------------------------------------------------------------------------
+'
+' Este código fue generado por una herramienta.
+' Versión de runtime:4.0.30319.42000
+'
+' Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si
+' se vuelve a generar el código.
+'
+'------------------------------------------------------------------------------
+
+Option Strict On
+Option Explicit On
+
diff --git a/My Project/Application.myapp b/My Project/Application.myapp
new file mode 100644
index 0000000..758895d
--- /dev/null
+++ b/My Project/Application.myapp
@@ -0,0 +1,10 @@
+
+
+ false
+ false
+ 0
+ true
+ 0
+ 1
+ true
+
diff --git a/My Project/AssemblyInfo.vb b/My Project/AssemblyInfo.vb
new file mode 100644
index 0000000..29302bd
--- /dev/null
+++ b/My Project/AssemblyInfo.vb
@@ -0,0 +1,46 @@
+Imports System
+Imports System.Reflection
+Imports System.Runtime.InteropServices
+
+' La información general sobre un ensamblado se controla mediante el siguiente
+' conjunto de atributos. Cambie estos atributos para modificar la información
+' asociada con un ensamblado.
+
+' Revisar los valores de los atributos del ensamblado
+
+
+
+
+
+
+
+
+
+
+'El siguiente GUID sirve como identificador de typelib si este proyecto se expone a COM
+
+
+' La información de versión de un ensamblado consta de los cuatro valores siguientes:
+'
+' Versión principal
+' Versión secundaria
+' Número de compilación
+' Revisión
+'
+' Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión
+' mediante el asterisco ('*'), como se muestra a continuación:
+'
+
+
+
+
+
+' Cambios en la versión 2.0.0.1
+'
+' 26/02/2025 Se elimina
+
+
+' Cambios en la versión 2.0.0.0
+'
+' 07/01/2025 Se cambia a la versión 52.0.0.0 de fluentftp
+' 07/01/2025 Se quitan los using y se cambian por dim en funciones asincronas
diff --git a/My Project/Resources.Designer.vb b/My Project/Resources.Designer.vb
new file mode 100644
index 0000000..f3b24af
--- /dev/null
+++ b/My Project/Resources.Designer.vb
@@ -0,0 +1,63 @@
+'------------------------------------------------------------------------------
+'
+' Este código fue generado por una herramienta.
+' Versión de runtime:4.0.30319.42000
+'
+' Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si
+' se vuelve a generar el código.
+'
+'------------------------------------------------------------------------------
+
+Option Strict On
+Option Explicit On
+
+Imports System
+
+Namespace My.Resources
+
+ 'StronglyTypedResourceBuilder generó automáticamente esta clase
+ 'a través de una herramienta como ResGen o Visual Studio.
+ 'Para agregar o quitar un miembro, edite el archivo .ResX y, a continuación, vuelva a ejecutar ResGen
+ 'con la opción /str o recompile su proyecto de VS.
+ '''
+ ''' Clase de recurso fuertemente tipado, para buscar cadenas traducidas, etc.
+ '''
+ _
+ Friend Module Resources
+
+ Private resourceMan As Global.System.Resources.ResourceManager
+
+ Private resourceCulture As Global.System.Globalization.CultureInfo
+
+ '''
+ ''' Devuelve la instancia de ResourceManager almacenada en caché utilizada por esta clase.
+ '''
+ _
+ Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
+ Get
+ If Object.ReferenceEquals(resourceMan, Nothing) Then
+ Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("tsFluentFTP.Resources", GetType(Resources).Assembly)
+ resourceMan = temp
+ End If
+ Return resourceMan
+ End Get
+ End Property
+
+ '''
+ ''' Reemplaza la propiedad CurrentUICulture del subproceso actual para todas las
+ ''' búsquedas de recursos mediante esta clase de recurso fuertemente tipado.
+ '''
+ _
+ Friend Property Culture() As Global.System.Globalization.CultureInfo
+ Get
+ Return resourceCulture
+ End Get
+ Set
+ resourceCulture = value
+ End Set
+ End Property
+ End Module
+End Namespace
diff --git a/My Project/Resources.resx b/My Project/Resources.resx
new file mode 100644
index 0000000..af7dbeb
--- /dev/null
+++ b/My Project/Resources.resx
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/My Project/Settings.Designer.vb b/My Project/Settings.Designer.vb
new file mode 100644
index 0000000..cde4b22
--- /dev/null
+++ b/My Project/Settings.Designer.vb
@@ -0,0 +1,73 @@
+'------------------------------------------------------------------------------
+'
+' Este código fue generado por una herramienta.
+' Versión de runtime:4.0.30319.42000
+'
+' Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si
+' se vuelve a generar el código.
+'
+'------------------------------------------------------------------------------
+
+Option Strict On
+Option Explicit On
+
+
+Namespace My
+
+ _
+ Partial Friend NotInheritable Class MySettings
+ Inherits Global.System.Configuration.ApplicationSettingsBase
+
+ Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
+
+#Region "Funcionalidad para autoguardar My.Settings"
+#If _MyType = "WindowsForms" Then
+ Private Shared addedHandler As Boolean
+
+ Private Shared addedHandlerLockObject As New Object
+
+ _
+ Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs)
+ If My.Application.SaveMySettingsOnExit Then
+ My.Settings.Save()
+ End If
+ End Sub
+#End If
+#End Region
+
+ Public Shared ReadOnly Property [Default]() As MySettings
+ Get
+
+#If _MyType = "WindowsForms" Then
+ If Not addedHandler Then
+ SyncLock addedHandlerLockObject
+ If Not addedHandler Then
+ AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
+ addedHandler = True
+ End If
+ End SyncLock
+ End If
+#End If
+ Return defaultInstance
+ End Get
+ End Property
+ End Class
+End Namespace
+
+Namespace My
+
+ _
+ Friend Module MySettingsProperty
+
+ _
+ Friend ReadOnly Property Settings() As Global.tsFluentFTP.My.MySettings
+ Get
+ Return Global.tsFluentFTP.My.MySettings.Default
+ End Get
+ End Property
+ End Module
+End Namespace
diff --git a/My Project/Settings.settings b/My Project/Settings.settings
new file mode 100644
index 0000000..85b890b
--- /dev/null
+++ b/My Project/Settings.settings
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/baget/Aplicacion.nuspec b/baget/Aplicacion.nuspec
new file mode 100644
index 0000000..8730415
--- /dev/null
+++ b/baget/Aplicacion.nuspec
@@ -0,0 +1,14 @@
+
+
+
+ tsFluentFTP
+ 1.0.0
+ Tecnosis
+ Tecnosis
+ false
+ Libreria ftp para .net 4.8
+
+
+
+
+
diff --git a/ftp.vb b/ftp.vb
new file mode 100644
index 0000000..0c62093
--- /dev/null
+++ b/ftp.vb
@@ -0,0 +1,591 @@
+Imports System.IO
+Imports System.Security.Authentication
+Imports System.Threading
+Imports FluentFTP
+Public Class ftp
+ Public Shared HoraControl As DateTime
+ Public Shared Function ObtenerFechaDeModificacion(Fichero As String, ServidorFTP As ServidorFTP) As Date
+ Try
+ Dim ftp As New FtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto)
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificado
+ If ServidorFTP.Pasivo Then
+ ftp.Config.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ ftp.Config.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ ftp.Config.RetryAttempts = ServidorFTP.Reintentos
+ ftp.Config.ConnectTimeout = ServidorFTP.Timeout
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Explicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Implicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ ftp.Config.EncryptionMode = FtpEncryptionMode.None
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ ftp.Encoding = System.Text.Encoding.UTF8
+ If ftp.IsConnected = False Then ftp.Connect()
+ Return ftp.GetModifiedTime(Fichero)
+ ftp.Disconnect()
+ Catch EX As Exception
+ Throw
+ End Try
+ Return Nothing
+ End Function
+
+ Public Shared Sub DescargaFichero(Fichero As String, st As Stream, ServidorFTP As ServidorFTP, Optional Progreso As Action(Of FtpProgress) = Nothing)
+ Try
+ Dim ftp As New FtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto)
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificado
+ If ServidorFTP.Pasivo Then
+ ftp.Config.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ ftp.Config.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ ftp.Config.RetryAttempts = ServidorFTP.Reintentos
+ ftp.Config.ConnectTimeout = ServidorFTP.Timeout
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Explicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Implicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ ftp.Config.EncryptionMode = FtpEncryptionMode.None
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ ftp.Encoding = System.Text.Encoding.UTF8
+ If ftp.IsConnected = False Then ftp.Connect()
+ If Not ftp.DownloadStream(st, Fichero, , Progreso) Then Throw New Exception("No se ha podido descargar el fichero")
+ ftp.Disconnect()
+ Catch EX As Exception
+ Throw New Exception(EX.Message, EX)
+ End Try
+ End Sub
+
+
+ 'Public Shared Async Function DownloadFileAsync() As Task
+ ' Dim token = New CancellationToken()
+ ' Dim cfg As New FtpConfig
+ ' cfg.DataConnectionType = FtpDataConnectionType.PASV
+ ' cfg.EncryptionMode = FtpEncryptionMode.Implicit
+ ' cfg.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ ' Using ftp = New AsyncFtpClient("192.168.41.56", "GestionCOAS", "TsCOAS.2019-", 992, cfg)
+
+ ' Await ftp.Connect(token)
+
+ ' ' define the progress tracking callback
+ ' Dim progress As Progress(Of FtpProgress) = New Progress(Of FtpProgress)(
+ ' Sub(p)
+ ' If p.Progress = 1 Then
+ ' ' all done!
+ ' Else
+ ' ' percent done = (p.Progress * 100)
+ ' End If
+ ' End Sub)
+
+ ' ' download a file with progress tracking
+ ' Await ftp.DownloadFile("C:\TMP\PRUEBA.BIN", "/FIRMADOS_COLEGIADOS/0761/0761-100010.002_001.fir", FtpLocalExists.Resume, FtpVerify.None, progress, token)
+
+ ' End Using
+ 'End Function
+
+ Public Shared Async Function DescargaFicheroAsync(Fichero As String, st As Stream, ServidorFTP As ServidorFTP, Optional Progreso As IProgress(Of FtpProgress) = Nothing, Optional ByVal Verificacion As FtpVerify = FtpVerify.None, Optional ct As Threading.CancellationTokenSource = Nothing) As Tasks.Task(Of FtpStatus)
+ Try
+ Dim cfg As New FtpConfig
+ If ServidorFTP.Pasivo Then
+ cfg.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ cfg.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ cfg.RetryAttempts = ServidorFTP.Reintentos
+ cfg.ConnectTimeout = ServidorFTP.Timeout
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ cfg.EncryptionMode = FtpEncryptionMode.Explicit
+ cfg.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ cfg.EncryptionMode = FtpEncryptionMode.Implicit
+ cfg.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ cfg.EncryptionMode = FtpEncryptionMode.None
+ cfg.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ ' Using ftp As AsyncFtpClient = New AsyncFtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto, cfg)
+ Dim ftp As AsyncFtpClient = New AsyncFtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto, cfg)
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificadoAsync
+ Dim t As FtpStatus
+ ftp.Encoding = System.Text.Encoding.UTF8
+ If ct Is Nothing Then
+ Await ftp.Connect()
+ t = Await ftp.DownloadStream(st, Fichero,, Progreso)
+ Else
+ Await ftp.Connect(ct.Token)
+ t = Await ftp.DownloadStream(st, Fichero, , Progreso, ct.Token)
+ End If
+ If t = FtpStatus.Failed Then Throw New Exception("Error descargando fichero " & Fichero)
+ If ct IsNot Nothing Then
+ Await ftp.Disconnect(ct.Token)
+ Else
+ Await ftp.Disconnect
+ End If
+ Return t
+ ' End Using
+ Catch EX As Exception
+ Throw New Exception(EX.Message, EX)
+ End Try
+ End Function
+
+ Public Shared Async Function DescargaFicheroAsync(FicheroLocal As String, FicheroRemoto As String, ServidorFTP As ServidorFTP, Optional Progreso As IProgress(Of FtpProgress) = Nothing, Optional ByVal Verificacion As FtpVerify = FtpVerify.None, Optional ct As Threading.CancellationTokenSource = Nothing) As Tasks.Task(Of FtpStatus)
+ Try
+ Dim cfg As New FtpConfig
+ If ServidorFTP.Pasivo Then
+ cfg.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ cfg.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ cfg.RetryAttempts = ServidorFTP.Reintentos
+ cfg.ConnectTimeout = ServidorFTP.Timeout
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ cfg.EncryptionMode = FtpEncryptionMode.Explicit
+ cfg.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ cfg.EncryptionMode = FtpEncryptionMode.Implicit
+ cfg.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ cfg.EncryptionMode = FtpEncryptionMode.None
+ cfg.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ ' Using ftp As AsyncFtpClient = New AsyncFtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto, cfg)
+ Dim ftp As AsyncFtpClient = New AsyncFtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto, cfg)
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificadoAsync
+ Dim t As FtpStatus
+ ftp.Encoding = System.Text.Encoding.UTF8
+ If ct Is Nothing Then
+ Await ftp.Connect()
+ t = Await ftp.DownloadFile(FicheroLocal, FicheroRemoto, FtpLocalExists.Overwrite, Verificacion, Progreso)
+ Else
+ Await ftp.Connect(ct.Token)
+ t = Await ftp.DownloadFile(FicheroLocal, FicheroRemoto, FtpLocalExists.Overwrite, Verificacion, Progreso, ct.Token)
+ End If
+ If t = FtpStatus.Failed Then Throw New Exception("Error descargando fichero " & FicheroLocal & " de " & FicheroRemoto & " ")
+ If ct IsNot Nothing Then
+ Await ftp.Disconnect(ct.Token)
+ Else
+ Await ftp.Disconnect
+ End If
+ Return t
+ 'End Using
+ Catch EX As Exception
+ Throw New Exception(EX.Message, EX)
+ End Try
+ End Function
+
+
+
+ Public Shared Sub DescargaFichero(FicheroLocal As String, FicheroRemoto As String, ServidorFTP As ServidorFTP, Optional Progreso As Action(Of FtpProgress) = Nothing, Optional ByVal Verificacion As FtpVerify = FtpVerify.None)
+ Try
+ Dim ftp As New FtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto)
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificado
+ If ServidorFTP.Pasivo Then
+ ftp.Config.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ ftp.Config.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ ftp.Config.RetryAttempts = ServidorFTP.Reintentos
+ ftp.Config.ConnectTimeout = ServidorFTP.Timeout
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Explicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Implicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ ftp.Config.EncryptionMode = FtpEncryptionMode.None
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ ftp.Encoding = System.Text.Encoding.UTF8
+ If ftp.IsConnected = False Then ftp.Connect()
+ If ftp.DownloadFile(FicheroLocal, FicheroRemoto, FtpLocalExists.Overwrite, Verificacion, Progreso) = FtpStatus.Failed Then Throw New Exception("No se ha podido descargar el fichero " & FicheroRemoto & " en " & FicheroLocal)
+
+ ftp.Disconnect()
+ Catch EX As Exception
+ Throw New Exception(EX.Message, EX)
+ End Try
+ End Sub
+ Public Shared Async Function EnviaFicheroAsync(FicheroOrigen As String, FicheroDestino As String, ServidorFTP As ServidorFTP, Optional Progreso As IProgress(Of FtpProgress) = Nothing, Optional Verificacion As FtpVerify = FtpVerify.None, Optional ct As Threading.CancellationTokenSource = Nothing) As Tasks.Task(Of FtpStatus)
+ Try
+ Dim cfg As New FtpConfig
+ If ServidorFTP.Pasivo Then
+ cfg.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ cfg.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ cfg.RetryAttempts = ServidorFTP.Reintentos
+ cfg.ConnectTimeout = ServidorFTP.Timeout
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ cfg.EncryptionMode = FtpEncryptionMode.Explicit
+ cfg.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ cfg.EncryptionMode = FtpEncryptionMode.Implicit
+ cfg.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ cfg.EncryptionMode = FtpEncryptionMode.None
+ cfg.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ Dim ftp As AsyncFtpClient = New AsyncFtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto, cfg)
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificadoAsync
+ ftp.Encoding = System.Text.Encoding.UTF8
+ Dim t As FtpStatus
+ If ct Is Nothing Then
+ Await ftp.Connect()
+ t = Await ftp.UploadFile(FicheroOrigen, FicheroDestino, FtpRemoteExists.Overwrite, False, Verificacion, Progreso)
+ Else
+ Await ftp.Connect(ct.Token)
+ t = Await ftp.UploadFile(FicheroOrigen, FicheroDestino, FtpRemoteExists.Overwrite, False, Verificacion, Progreso, ct.Token)
+ End If
+ If ct IsNot Nothing Then
+ Await ftp.Disconnect(ct.Token)
+ Else
+ Await ftp.Disconnect
+ End If
+ If t = FtpStatus.Failed Then Throw New Exception("Error enviado fichero " & FicheroOrigen & " a " & FicheroDestino)
+ Return t
+ ' End Using
+ Catch EX As Exception
+ Throw New Exception(EX.Message, EX)
+ End Try
+
+ End Function
+ Public Shared Async Function RenombraFicheroAsync(FicheroOrigen As String, FicheroDestino As String, ServidorFTP As ServidorFTP) As Tasks.Task(Of FtpStatus)
+ Try
+ Dim cfg As New FtpConfig
+ If ServidorFTP.Pasivo Then
+ cfg.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ cfg.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ cfg.RetryAttempts = ServidorFTP.Reintentos
+ cfg.ConnectTimeout = ServidorFTP.Timeout
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ cfg.EncryptionMode = FtpEncryptionMode.Explicit
+ cfg.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ cfg.EncryptionMode = FtpEncryptionMode.Implicit
+ cfg.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ cfg.EncryptionMode = FtpEncryptionMode.None
+ cfg.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ Dim ftp As AsyncFtpClient = New AsyncFtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto, cfg)
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificadoAsync
+
+ ftp.Encoding = System.Text.Encoding.UTF8
+ If ftp.IsConnected = False Then Await ftp.Connect()
+ If Not ftp.Capabilities.Contains(FtpCapability.MDTM) Then ftp.Capabilities.Add(FtpCapability.MDTM)
+
+ ' MsgBox("renombrando fichero " & FicheroOrigen & " a " & FicheroDestino)
+ Dim t = Await ftp.MoveFile(FicheroOrigen, FicheroDestino, FtpRemoteExists.Overwrite)
+ ' MsgBox(t)
+ Await ftp.Disconnect()
+ If t = FtpStatus.Failed Then Throw New Exception("Error renombrando fichero " & FicheroOrigen & " a " & FicheroDestino)
+ Return t
+ ' End Using
+ Catch EX As Exception
+ MsgBox(EX.Message)
+ Throw New PKICOAS.TSException(EX.Message, EX, "FTP_ERROR.DESCONOCIDO", )
+ End Try
+ End Function
+
+
+ Public Shared Sub EnviaFichero(FicheroOrigen As String, FicheroDestino As String, ServidorFTP As ServidorFTP, Optional Progreso As Action(Of FtpProgress) = Nothing, Optional Verificacion As FtpVerify = FtpVerify.None)
+ Try
+ Dim ftp As New FtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto)
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificado
+ If ServidorFTP.Pasivo Then
+ ftp.Config.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ ftp.Config.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ ftp.Config.RetryAttempts = ServidorFTP.Reintentos
+ ftp.Config.ConnectTimeout = ServidorFTP.Timeout
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Explicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Implicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ ftp.Config.EncryptionMode = FtpEncryptionMode.None
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ ftp.Encoding = System.Text.Encoding.UTF8
+ If ftp.IsConnected = False Then ftp.Connect()
+ If Not ftp.Capabilities.Contains(FtpCapability.MDTM) Then ftp.Capabilities.Add(FtpCapability.MDTM)
+ Dim t = ftp.UploadFile(FicheroOrigen, FicheroDestino, FtpRemoteExists.Overwrite, False, Verificacion, Progreso)
+ If t = FtpStatus.Failed Then Throw New Exception("Error enviando fichero " & FicheroOrigen & " a " & FicheroDestino & " ")
+ ftp.Disconnect()
+ Catch EX As Exception
+ Throw New Exception(EX.Message, EX)
+ End Try
+ End Sub
+
+ Public Shared Sub EnviaFichero(FicheroOrigen As Byte(), FicheroDestino As String, ServidorFTP As ServidorFTP, Optional Progreso As Action(Of FtpProgress) = Nothing)
+ Try
+ Dim ftp As New FtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto)
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificado
+ If ServidorFTP.Pasivo Then
+ ftp.Config.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ ftp.Config.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ ftp.Config.RetryAttempts = ServidorFTP.Reintentos
+ ftp.Config.ConnectTimeout = ServidorFTP.Timeout
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Explicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Implicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ ftp.Config.EncryptionMode = FtpEncryptionMode.None
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ ftp.Encoding = System.Text.Encoding.UTF8
+ If ftp.IsConnected = False Then ftp.Connect()
+ If Not ftp.Capabilities.Contains(FtpCapability.MDTM) Then ftp.Capabilities.Add(FtpCapability.MDTM)
+ Dim t = ftp.UploadBytes(FicheroOrigen, FicheroDestino, FtpRemoteExists.Overwrite, False, Progreso)
+ If t = FtpStatus.Failed Then Throw New Exception("Error enviando fichero ")
+ ftp.Disconnect()
+ Catch EX As Exception
+ Throw
+ End Try
+ End Sub
+
+
+
+ Public Shared Sub CreaDirectorio(Directorio As String, ServidorFTP As ServidorFTP)
+ Try
+ Dim ftp As New FtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto)
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificado
+ If ServidorFTP.Pasivo Then
+ ftp.Config.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ ftp.Config.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ ftp.Config.RetryAttempts = ServidorFTP.Reintentos
+ ftp.Config.ConnectTimeout = ServidorFTP.Timeout
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Explicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Implicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ ftp.Config.EncryptionMode = FtpEncryptionMode.None
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ ftp.Encoding = System.Text.Encoding.UTF8
+ If ftp.IsConnected = False Then ftp.Connect()
+
+ If Not ftp.DirectoryExists(Directorio) Then
+ ftp.CreateDirectory(Directorio, True)
+ End If
+ ftp.Disconnect()
+ Catch EX As Exception
+ Throw
+ End Try
+ End Sub
+
+ Public Shared Sub EliminaFichero(Fichero As String, ServidorFTP As ServidorFTP)
+ Try
+ Dim ftp As New FtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto)
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificado
+ If ServidorFTP.Pasivo Then
+ ftp.Config.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ ftp.Config.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ ftp.Config.RetryAttempts = ServidorFTP.Reintentos
+ ftp.Config.ConnectTimeout = ServidorFTP.Timeout
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Explicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Implicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ ftp.Config.EncryptionMode = FtpEncryptionMode.None
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ ftp.Encoding = System.Text.Encoding.UTF8
+ If ftp.IsConnected = False Then ftp.Connect()
+ ftp.DeleteFile(Fichero)
+ ftp.Disconnect()
+ Catch EX As Exception
+ Throw
+ End Try
+ End Sub
+
+ Public Shared Function ExisteFichero(Fichero As String, ServidorFTP As ServidorFTP) As Boolean
+ Try
+ Dim ftp As New FtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto)
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificado
+ If ServidorFTP.Pasivo Then
+ ftp.Config.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ ftp.Config.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ ftp.Config.RetryAttempts = ServidorFTP.Reintentos
+ ftp.Config.ConnectTimeout = ServidorFTP.Timeout
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Explicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Implicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ ftp.Config.EncryptionMode = FtpEncryptionMode.None
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ ftp.Encoding = System.Text.Encoding.UTF8
+ If ftp.IsConnected = False Then ftp.Connect()
+ If Not ftp.Capabilities.Contains(FtpCapability.MDTM) Then ftp.Capabilities.Add(FtpCapability.MDTM)
+ Return ftp.FileExists(Fichero)
+ ftp.Disconnect()
+ Catch EX As Exception
+ Throw
+ End Try
+ End Function
+
+
+
+ Public Shared Sub RenombraFichero(FicheroOrigen As String, FicheroDestino As String, ServidorFTP As ServidorFTP)
+ Try
+ Dim ftp As New FtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto)
+ If ServidorFTP.Pasivo Then
+ ftp.Config.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ ftp.Config.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ ftp.Config.RetryAttempts = ServidorFTP.Reintentos
+ ftp.Config.ConnectTimeout = ServidorFTP.Timeout
+ AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificado
+ Select Case ServidorFTP.Seguridad
+ Case SeguridadFTP.Explicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Explicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case SeguridadFTP.Implicita
+ ftp.Config.EncryptionMode = FtpEncryptionMode.Implicit
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.Tls + Security.Authentication.SslProtocols.Tls11 + Security.Authentication.SslProtocols.Tls12
+ Case Else
+ ftp.Config.EncryptionMode = FtpEncryptionMode.None
+ ftp.Config.SslProtocols = Security.Authentication.SslProtocols.None
+ End Select
+ ftp.Encoding = System.Text.Encoding.UTF8
+ If ftp.IsConnected = False Then ftp.Connect()
+ If Not ftp.Capabilities.Contains(FtpCapability.MDTM) Then ftp.Capabilities.Add(FtpCapability.MDTM)
+ ftp.MoveFile(FicheroOrigen, FicheroDestino, FtpRemoteExists.Overwrite)
+ ftp.Disconnect()
+ Catch EX As PKICOAS.TSException
+ Throw EX
+ Catch EX As Exception
+ Throw New PKICOAS.TSException(EX.Message, EX, "FTP_ERROR.DESCONOCIDO", )
+ End Try
+ End Sub
+ 'Public Shared Sub MueveFicheros(PatronFicheroOrigen As String, DirectorioDestino As String, ServidorFTP As ServidorFTP)
+ ' Try
+ ' Dim ftp As New FtpClient(ServidorFTP.Servidor, ServidorFTP.Puerto, ServidorFTP.Usuario, ServidorFTP.Contraseña)
+ ' If ServidorFTP.Pasivo Then ftp.DataConnectionType = ServidorFTP.Pasivo
+ ' AddHandler ftp.ValidateCertificate, AddressOf ValidarCertificado
+ ' Select Case ServidorFTP.Seguridad
+ ' Case SeguridadFTP.Explicita
+ ' ftp.EncryptionMode = FtpEncryptionMode.Explicit
+ ' ftp.SslProtocols = Security.Authentication.SslProtocols.Tls
+ ' Case SeguridadFTP.Implicita
+ ' ftp.EncryptionMode = FtpEncryptionMode.Implicit
+ ' ftp.SslProtocols = Security.Authentication.SslProtocols.Tls
+ ' Case Else
+ ' ftp.EncryptionMode = FtpEncryptionMode.None
+ ' End Select
+ ' ftp.Encoding = System.Text.Encoding.UTF8
+
+ ' Dim lf = ftp.GetListing(PatronFicheroOrigen)
+ ' If DirectorioDestino.EndsWith("/") = False Then DirectorioDestino &= "/"
+ ' For Each F In lf
+ ' ftp.Rename(F.FullName, DirectorioDestino & F.Name)
+ ' Next
+ ' Catch EX As PKICOAS.TSException
+ ' Throw EX
+ ' Catch EX As Exception
+ ' Throw New PKICOAS.TSException(EX.Message, EX, "FTP_ERROR.DESCONOCIDO", )
+ ' End Try
+ 'End Sub
+
+ Public Shared Function ObtieneListaFicheros(Ruta As String, ServidorFTP As ServidorFTP) As FtpListItem()
+ Dim ftp As New FtpClient(ServidorFTP.Servidor, ServidorFTP.Usuario, ServidorFTP.Contraseña, ServidorFTP.Puerto)
+ If ServidorFTP.Pasivo Then
+ ftp.Config.DataConnectionType = FtpDataConnectionType.PASV
+ Else
+ ftp.Config.DataConnectionType = FtpDataConnectionType.AutoActive
+ End If
+ ftp.Config.RetryAttempts = ServidorFTP.Reintentos
+ ftp.Config.ConnectTimeout = ServidorFTP.Timeout
+ ' ftp.Config.ListingCulture = Globalization.CultureInfo.CurrentCulture
+ If ftp.IsConnected = False Then ftp.Connect()
+ Dim lf = ftp.GetListing(Ruta)
+ ftp.Disconnect()
+ Return lf
+ End Function
+
+ Private Shared Sub ValidarCertificado(control As FtpClient, e As FtpSslValidationEventArgs)
+ e.Accept = True
+ End Sub
+ Private Shared Sub ValidarCertificadoAsync(control As AsyncFtpClient, e As FtpSslValidationEventArgs)
+ e.Accept = True
+ End Sub
+End Class
+
+Public Class ServidorFTP
+ Property Servidor As String
+ Property Puerto As Integer
+ Property Seguridad As SeguridadFTP
+ Property Pasivo As Boolean
+ Property Timeout As Integer
+ Property Usuario As String
+ Property Contraseña As String
+ Property Reintentos As Integer
+ Public Sub New(Servidor As String, Puerto As Integer, Usuario As String, Contraseña As String, Optional Seguridad As SeguridadFTP = SeguridadFTP.Ninguna, Optional Pasivo As Boolean = False, Optional timeout As Integer = 20000, Optional Reintentos As Integer = 3)
+ _Servidor = Servidor
+ _Puerto = Puerto
+ _Seguridad = Seguridad
+ _Pasivo = Pasivo
+ _Timeout = timeout
+ _Usuario = Usuario
+ _Contraseña = Contraseña
+ _Reintentos = Reintentos
+ End Sub
+End Class
+Public Enum SeguridadFTP
+ Ninguna = 0
+ Implicita = 1
+ Explicita = 2
+ ExplicitaConControl = 3
+ ExplicitaControlOpcional = 4
+ SoloControl = 5
+ SoloDatos = 6
+End Enum
+
diff --git a/tsFluentFTP.sln b/tsFluentFTP.sln
new file mode 100644
index 0000000..6e90ab5
--- /dev/null
+++ b/tsFluentFTP.sln
@@ -0,0 +1,33 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.10.34916.146
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "tsFluentFTP", "tsFluentFTP.vbproj", "{6C286F93-3041-46C3-8AF2-A2921F87625E}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {6C286F93-3041-46C3-8AF2-A2921F87625E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6C286F93-3041-46C3-8AF2-A2921F87625E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6C286F93-3041-46C3-8AF2-A2921F87625E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6C286F93-3041-46C3-8AF2-A2921F87625E}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {2C52EF4B-5437-4ECF-A212-DDE67F854DD6}
+ EndGlobalSection
+ GlobalSection(TeamFoundationVersionControl) = preSolution
+ SccNumberOfProjects = 2
+ SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
+ SccTeamFoundationServer = http://ts-devopss:81/tecnosiscollection
+ SccProjectUniqueName0 = tsFluentFTP.vbproj
+ SccLocalPath0 = .
+ SccLocalPath1 = .
+ EndGlobalSection
+EndGlobal
diff --git a/tsFluentFTP.vbproj b/tsFluentFTP.vbproj
new file mode 100644
index 0000000..632316f
--- /dev/null
+++ b/tsFluentFTP.vbproj
@@ -0,0 +1,131 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {6C286F93-3041-46C3-8AF2-A2921F87625E}
+ Library
+ tsFluentFTP
+ tsFluentFTP
+ 512
+ Windows
+ v4.8
+ SAK
+ SAK
+ SAK
+ SAK
+
+
+
+ true
+ full
+ true
+ true
+ bin\Debug\
+ tsFluentFTP.xml
+ 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
+ false
+
+
+ pdbonly
+ false
+ true
+ true
+ bin\Release\
+ tsFluentFTP.xml
+ 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
+ false
+
+
+ On
+
+
+ Binary
+
+
+ Off
+
+
+ On
+
+
+
+ ..\..\Controles\Binarios\PKICOAS\PKICOAS.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ True
+ Application.myapp
+ True
+
+
+ True
+ True
+ Resources.resx
+
+
+ True
+ Settings.settings
+ True
+
+
+
+
+ VbMyResourcesResXFileCodeGenerator
+ Resources.Designer.vb
+ My.Resources
+ Designer
+
+
+
+
+
+ MyApplicationCodeGenerator
+ Application.Designer.vb
+
+
+ SettingsSingleFileGenerator
+ My
+ Settings.Designer.vb
+
+
+
+
+ 53.0.2
+
+
+
+
+
\ No newline at end of file