Upload-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] **

Upload 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
       'PutFiles Method is used to upload complete directory structure of some local folder to server.
       'In combination with LoopItem Event we can upload only files with specific filenames.
       wodSFTP1.PutFiles "c:\somelocalfolder", "/home/somefolder", 0
    Else
       'Receive connection error here. If there were any.
       MsgBox "Connected Error: " & ErrorText
    End If
End Sub

'PutFiles Method trigger LoopItem Event.
'LoopItem Event fires before files upload process.
'Inside this Event we can specify which files we want to upload.
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 local files for desire extension.
         If Right$(LocalFile, 4) = ".exe" 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
        'PutFiles Method is used to upload complete directory structure of some local folder to server.
        'In combination with LoopItem Event we can upload only files with specific filenames.
        wodSFTP1.PutFiles("c:\somelocalfolder", "/home/somefolder", 0)
    Else
        'Receive connection error here. If there were any.
        MsgBox("Connected Error: " + Args.Error.Message)
    End If
End Sub

'PutFiles Method trigger LoopItem Event.
'LoopItem Event fires before files upload process.
'Inside this Event we can specify which files we want to upload.
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 local files for desire extension.
        If Args.LocalFile.EndsWith(".exe") 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)
    {
        //PutFiles Method is used to upload complete directory structure of some local folder to server.
        //In combination with LoopItem Event we can upload only files with specific filenames.
        wodSFTP1.PutFiles("c:\\somelocalfolder", "/home/somefolder",0);
    }
    else
        //Receive connection error here. If there were any.
        MessageBox.Show("Connected Error: " + Args.Error.Message);

}

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

}