Download-files-with-specific-filename-extension-using-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 files with specific filename extension using SFTP protocol
VB code
Dim WithEvents wodSFTP1 As wodSFTPCom
Private Sub Form_Load()
    Set wodSFTP1 = New wodSFTPCom
    
    'Authenticate with server using hostname, login, password.
    wodSFTP1.HostName = "your_hostname"
    wodSFTP1.Login = "your_login"
    wodSFTP1.Password = "your_password"
    wodSFTP1.Connect
End Sub

'Connected Event is triggered after connection with server is established.
Private Sub wodSFTP1_Connected(ByVal ErrorCode As Integer, ByVal ErrorText As String)
    If ErrorCode = 0 Then
       'GetFiles Method is used to download complete directory structure of some folder on server to local disk.
       'In combination with LoopItem Event we can download only specific filenames.
       wodSFTP1.GetFiles "c:\somelocalfolder", "/home/somefolder", 0
    Else
       'Receive connection error here. If there were any.
       MsgBox "Connected Error: " & ErrorText
    End If
End Sub

'GetFiles Method trigger LoopItem Event.
'LoopItem Event fires before files download process.
'Inside this Event we can specify which files we want to download.
Private Sub wodSFTP1_LoopItem(LocalFile As String, RemoteFile As String, ByVal ItemType As wodSFTPCOMLib.DirItemTypes, Skip As Boolean)
    If ItemType = typeDirectory Then
        Skip = False
    Else
        'Check remote files for desire extension.
         If Right$(RemoteFile, 4) = ".txt" Then
            Skip = False
         Else
            Skip = True
         End If
    End If
End Sub
VB.NET code
Dim WithEvents wodSFTP1 As WeOnlyDo.Client.SFTP
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    wodSFTP1 = New WeOnlyDo.Client.SFTP

    'Authenticate with server using hostname, login, password.
    wodSFTP1.Hostname = "your_hostname"
    wodSFTP1.Login = "your_login"
    wodSFTP1.Password = "your_password"
    wodSFTP1.Connect()
End Sub

'Connected Event is triggered after connection with server is established.
Private Sub wodSFTP1_ConnectedEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.SFTP.ConnectedArgs) Handles wodSFTP1.ConnectedEvent
    If (Args.Error Is Nothing) Then
        'GetFiles Method is used to download complete directory structure of some folder on server to local disk.
        'In combination with LoopItem Event we can download only specific filenames.
        wodSFTP1.GetFiles("c:\somelocalfolder", "/home/somefolder", 0)
    Else
        'Receive connection error here. If there were any.
        MsgBox("Connected Error: " + Args.Error.Message)
    End If
End Sub

'GetFiles Method trigger LoopItem Event.
'LoopItem Event fires before files download process.
'Inside this Event we can specify which files we want to download.
Private Sub wodSFTP1_LoopItemEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.SFTP.LoopArgs) Handles wodSFTP1.LoopItemEvent
    If Args.ItemType = WeOnlyDo.Client.SFTP.DirItemTypes.Directory Then
        Args.Skip = False
    Else
        'Check remote files for desire extension.
        If Args.RemoteFile.EndsWith(".txt") Then
            Args.Skip = False
        Else
            Args.Skip = True
        End If
    End If
End Sub
C# code
WeOnlyDo.Client.SFTP wodSFTP1;
private void Form1_Load(object sender, EventArgs e)
{
    wodSFTP1 = new WeOnlyDo.Client.SFTP();
    wodSFTP1.ConnectedEvent += new WeOnlyDo.Client.SFTP.ConnectedDelegate(wodSFTP1_ConnectedEvent);
    wodSFTP1.LoopItemEvent += new WeOnlyDo.Client.SFTP.LoopDelegate(wodSFTP1_LoopItemEvent);

    //Authenticate with server using hostname, login, password.
    wodSFTP1.Hostname = "your_hostname";
    wodSFTP1.Login = "your_login";
    wodSFTP1.Password = "your_password";
    wodSFTP1.Connect();
}

//Connected Event is triggered after connection with server is established.
void wodSFTP1_ConnectedEvent(object Sender, WeOnlyDo.Client.SFTP.ConnectedArgs Args)
{
    if (Args.Error == null)
    {
        //GetFiles Method is used to download complete directory structure of some folder on server to local disk.
        //In combination with LoopItem Event we can download only specific filenames.
        wodSFTP1.GetFiles("c:\\somelocalfolder", "/home/somefolder",0);
    }
    else
        //Receive connection error here. If there were any.
        MessageBox.Show("Connected Error: " + Args.Error.Message);

}

//GetFiles Method trigger LoopItem Event.
//LoopItem Event fires before files download process.
//Inside this Event we can specify which files we want to download.
void wodSFTP1_LoopItemEvent(object Sender, WeOnlyDo.Client.SFTP.LoopArgs Args)
{
    if (Args.ItemType == WeOnlyDo.Client.SFTP.DirItemTypes.Directory)
    {
        Args.Skip = false;
    }
    else
    {
        //Check remote files for desire extension.
        if (Args.RemoteFile.EndsWith(".txt"))
        {
            Args.Skip = false;	
        }
        else
        {
            Args.Skip = true;
        }
    }

}