Agregar archivos de proyecto.
This commit is contained in:
13
My Project/Application.Designer.vb
generated
Normal file
13
My Project/Application.Designer.vb
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
10
My Project/Application.myapp
Normal file
10
My Project/Application.myapp
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<MySubMain>false</MySubMain>
|
||||
<SingleInstance>false</SingleInstance>
|
||||
<ShutdownMode>0</ShutdownMode>
|
||||
<EnableVisualStyles>true</EnableVisualStyles>
|
||||
<AuthenticationMode>0</AuthenticationMode>
|
||||
<ApplicationType>1</ApplicationType>
|
||||
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
|
||||
</MyApplicationData>
|
||||
46
My Project/AssemblyInfo.vb
Normal file
46
My Project/AssemblyInfo.vb
Normal file
@@ -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
|
||||
|
||||
<Assembly: AssemblyTitle("tsFluentFTP")>
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("")>
|
||||
<Assembly: AssemblyProduct("tsFluentFTP")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2018")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
'El siguiente GUID sirve como identificador de typelib si este proyecto se expone a COM
|
||||
<Assembly: Guid("be68d4c0-595c-4ca9-b4ff-923ce3d21c8e")>
|
||||
|
||||
' 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:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("2.0.0.1")>
|
||||
<Assembly: AssemblyFileVersion("2.0.0.1")>
|
||||
|
||||
|
||||
' 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
|
||||
63
My Project/Resources.Designer.vb
generated
Normal file
63
My Project/Resources.Designer.vb
generated
Normal file
@@ -0,0 +1,63 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
'''<summary>
|
||||
''' Clase de recurso fuertemente tipado, para buscar cadenas traducidas, etc.
|
||||
'''</summary>
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
Friend Module Resources
|
||||
|
||||
Private resourceMan As Global.System.Resources.ResourceManager
|
||||
|
||||
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||
|
||||
'''<summary>
|
||||
''' Devuelve la instancia de ResourceManager almacenada en caché utilizada por esta clase.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
'''<summary>
|
||||
''' Reemplaza la propiedad CurrentUICulture del subproceso actual para todas las
|
||||
''' búsquedas de recursos mediante esta clase de recurso fuertemente tipado.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend Property Culture() As Global.System.Globalization.CultureInfo
|
||||
Get
|
||||
Return resourceCulture
|
||||
End Get
|
||||
Set
|
||||
resourceCulture = value
|
||||
End Set
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
117
My Project/Resources.resx
Normal file
117
My Project/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
73
My Project/Settings.Designer.vb
generated
Normal file
73
My Project/Settings.Designer.vb
generated
Normal file
@@ -0,0 +1,73 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' 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.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.5.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
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
|
||||
|
||||
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
|
||||
Friend Module MySettingsProperty
|
||||
|
||||
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
|
||||
Friend ReadOnly Property Settings() As Global.tsFluentFTP.My.MySettings
|
||||
Get
|
||||
Return Global.tsFluentFTP.My.MySettings.Default
|
||||
End Get
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
7
My Project/Settings.settings
Normal file
7
My Project/Settings.settings
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
14
baget/Aplicacion.nuspec
Normal file
14
baget/Aplicacion.nuspec
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<package >
|
||||
<metadata>
|
||||
<id>tsFluentFTP</id>
|
||||
<version>1.0.0</version>
|
||||
<authors>Tecnosis</authors>
|
||||
<owners>Tecnosis</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>Libreria ftp para .net 4.8</description>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="..\bin\Debug\tsFluentFTP.dll" target="lib\net48" />
|
||||
</files>
|
||||
</package>
|
||||
591
ftp.vb
Normal file
591
ftp.vb
Normal file
@@ -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
|
||||
|
||||
33
tsFluentFTP.sln
Normal file
33
tsFluentFTP.sln
Normal file
@@ -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
|
||||
131
tsFluentFTP.vbproj
Normal file
131
tsFluentFTP.vbproj
Normal file
@@ -0,0 +1,131 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{6C286F93-3041-46C3-8AF2-A2921F87625E}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>tsFluentFTP</RootNamespace>
|
||||
<AssemblyName>tsFluentFTP</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<MyType>Windows</MyType>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<DefineDebug>true</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DocumentationFile>tsFluentFTP.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DefineDebug>false</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DocumentationFile>tsFluentFTP.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionExplicit>On</OptionExplicit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionCompare>Binary</OptionCompare>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionStrict>Off</OptionStrict>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionInfer>On</OptionInfer>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="PKICOAS">
|
||||
<HintPath>..\..\Controles\Binarios\PKICOAS\PKICOAS.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Import Include="Microsoft.VisualBasic" />
|
||||
<Import Include="System" />
|
||||
<Import Include="System.Collections" />
|
||||
<Import Include="System.Collections.Generic" />
|
||||
<Import Include="System.Data" />
|
||||
<Import Include="System.Diagnostics" />
|
||||
<Import Include="System.Linq" />
|
||||
<Import Include="System.Xml.Linq" />
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ftp.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Resources.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Settings.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="baget\Aplicacion.nuspec" />
|
||||
<None Include="My Project\Application.myapp">
|
||||
<Generator>MyApplicationCodeGenerator</Generator>
|
||||
<LastGenOutput>Application.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
<None Include="My Project\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentFTP">
|
||||
<Version>53.0.2</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
Reference in New Issue
Block a user