ComponentPro UltimateSftp

      Create a WinForms application

      Language Filter: AllSend comments on this topic to ComponentPro

      This tutorial will walk you through creating a WinForms application and add Sftp control to it. It also shows how to:

      • Drag and Drop Sftp control from the Toolbox to your form.
      • Set Sftp properties.

      Creating a new project and adding SFTP control to it

      1. Start the Visual Studio .NET.
      2. From File menu, choose New, then choose Project.
      3. From the Project Creation dialog box, choose either Visual C# Projects or Visual Basic Projects then choose Windows Application. Specify a name and a location for the project, then click OK.
      4. Drag and drop the Sftp control from the Toolbox to the form.

        Another way is to add references to ComponentPro.Sftp.dll, ComponentPro.Common.dll, ComponentPro.FileSystem.dll, and ComponentPro.Network.dll assemblies. Please see Installation instruction for C# and Installation instruction for VB.NET for more details.
      5. Now right click on the SFTP component icon to show the context menu, click on the Properties... menu.
      6. Now make a quick application to test. Drag a Button onto the form.
      7. Add the following code to the button "OnClick" event handler. This code is for uploading a local file to an SFTP server.
        // Create a new class instance.
        Sftp client = new Sftp();
        
        // Connect to the SFTP server.
        client.Connect("localhost");
        
        // Authenticate.
        client.Authenticate("test", "test");
        
        // Upload local file 'c:\test.dat' to the default remote directory.
        client.UploadFile("c:\\test.dat", "test.dat");
        
        string defaultDir = client.GetCurrentDirectory();
        MessageBox.Show(string.Format("File has been successfully uploaded to '{0}'.", defaultDir));
        
        // Disconnect.
        client.Disconnect();
        
      8. Compile and execute the application by navigating to the Debug menu and choose Start. Click the button and you should see a message indicating that the file has been successfully uploaded to your SFTP server's default working directory in the MessageBox.