Downloading-multiple-files-using-the-FTP-FTPS-SFTP-protocol - WeOnlyDo Software example code



All

wodCrypt (12)
wodSSH (10)
wodSFTP (23)
wodSSHServer (1)
wodSSHTunnel (11)
wodSSHpackage
wodSFTPdll

wodSSH.NET (10)
wodSFTP.NET (24)
wodFtpDLX.NET (22)
wodWebServer.NET (10)

wodAppUpdate (13)
wodHttpDLX (8)
wodFtpDLX (22)
wodTelnetDLX
wodFTPServer (3)
wodWebServer (10)
wodVPN
wodXMPP (13)
All ** [Visual Basic] ** [C#] ** [VB.NET] **

Download multiple files using the FTP, SFTP or FTPS protocol
Set Protocol property to change the protocol in below code
VB code
Dim WithEvents wodFtpDLX1 As wodFtpDLXCom

Private Sub Form_Load()
    Set wodFtpDLX1 = New wodFtpDLXCom
    wodFtpDLX1.HostName = "xx"
    wodFtpDLX1.Login = "xx"
    wodFtpDLX1.Password = "xx"
    wodFtpDLX1.Connect
End Sub

'Once connected, the Connected event will fire and you should initiate the download using the GetFiles methdod from there. 
'Make sure you always use full paths when specifying local and remote paths, such as /home/joe/folder/files. So, a simple call like this:
Private Sub wodFtpDLX1_Connected(ByVal ErrorCode As Long, ByVal ErrorText As String
    If ErrorCode = 0 Then
        wodFtpDLX1.GetFiles "d:\", "/home/xx"
    End If
End Sub
'will download all files from the remote folder /home/xx . During the download, before each file is downloaded,
'the LoopItem event will be fired allowing you to skip file downloads if needed.
'This allows you to filter out any files you're not interested in from remote folder
Private Sub wodFtpDLX1_LoopItem(LocalFile As String, RemoteFile As String, ByVal ItemType As wodFtpDLXComLib.DirItemTypes, Skip As Boolean)
' we download only .txt files
    If InStr(1, RemoteFile, ".txt", vbTextCompare) < 1 Then
        Skip = True
    End If
End Sub

'when wodFtpDLX is finished, it will fire the Done event and you can disconnect from the server. 
Private Sub wodFtpDLX1_Done(ByVal ErrorCode As Long, ByVal ErrorText As String)
    wodFtpDLX1.Disconnect
End Sub
VB.NET code
Public Class Form1
Dim WithEvents wodFtpDLX1 As WeOnlyDo.Client.FtpDLX
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  wodFtpDLX1 = New WeOnlyDo.Client.FtpDLX
  wodFtpDLX1.Hostname = "xx"
  wodFtpDLX1.Login = "xx"
  wodFtpDLX1.Password = "xx"
  wodFtpDLX1.Connect()
End Sub

'Once connected, the Connected event will fire and you should initiate the download using the GetFiles methdod from there. 
'Make sure you always use full paths when specifying local and remote paths, such as /home/joe/folder/files. So, a simple call like this:
Private Sub wodFtpDLX1_ConnectedEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.FtpConnectedArgs) Handles wodFtpDLX1.ConnectedEvent
  wodFtpDLX1.GetFiles("d:\", "/home/xx", 0)
End Sub
'will download all files from the remote folder /home/xx . During the download, before each file is downloaded,
'the LoopItem event will be fired allowing you to skip file downloads if needed.
'This allows you to filter out any files you're not interested in from remote folder
Private Sub wodFtpDLX1_DoneEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.FtpDoneArgs) Handles wodFtpDLX1.DoneEvent
  wodFtpDLX1.Disconnect()
End Sub

'when wodFtpDLX is finished, it will fire the Done event and you can disconnect from the server. 
Private Sub wodFtpDLX1_LoopItemEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.FtpLoopArgs) Handles wodFtpDLX1.LoopItemEvent
  If Not Args.RemoteFile.EndsWith(".txt") Then
    Args.Skip = True
  End If
End Sub
End Class
C# code
WeOnlyDo.Client.FtpDLX wodFtpDLX1;
private void Form1_Load(object sender, EventArgs e)
{
    wodFtpDLX1 = new WeOnlyDo.Client.FtpDLX();
    wodFtpDLX1.ConnectedEvent += new WeOnlyDo.Client.FtpDLX.ConnectedDelegate(wodFtpDLX1_ConnectedEvent);
    wodFtpDLX1.DoneEvent += new WeOnlyDo.Client.FtpDLX.DoneDelegate(wodFtpDLX1_DoneEvent);
    wodFtpDLX1.LoopItemEvent += new WeOnlyDo.Client.FtpDLX.LoopDelegate(wodFtpDLX1_LoopItemEvent);

    wodFtpDLX1.Hostname = "xx";
    wodFtpDLX1.Login = "xx";
    wodFtpDLX1.Password = "xx";
    wodFtpDLX1.Connect();
}
//Once connected, the Connected event will fire and you should initiate the download using the GetFiles methdod from there. 
//Make sure you always use full paths when specifying local and remote paths, such as /home/joe/folder/files. So, a simple call like this:
void wodFtpDLX1_ConnectedEvent(object Sender, WeOnlyDo.Client.FtpConnectedArgs Args)
{
    wodFtpDLX1.GetFiles("d:\\", "/home/xx", 0);
}
//will download all files from the remote folder /home/xx . During the download, before each file is downloaded,
//the LoopItem event will be fired allowing you to skip file downloads if needed.
//This allows you to filter out any files you're not interested in from remote folder
void wodFtpDLX1_DoneEvent(object Sender, WeOnlyDo.Client.FtpDoneArgs Args)
{
    wodFtpDLX1.Disconnect();
}
//when wodFtpDLX is finished, it will fire the Done event and you can disconnect from the server.
void wodFtpDLX1_LoopItemEvent(object Sender, WeOnlyDo.Client.FtpLoopArgs Args)
{
    if (!Args.RemoteFile.EndsWith(".txt"))
        Args.Skip = true;
}