Using FTPConnection in Windows Forms

The following refers to Visual Studio.NET 2003.  Similar steps apply to VS.NET 2005 and SharpDevelop.

1. Adding FTPConnection to the Visual Studio Toolbox

In order to be able to drop an FTPConnection onto a Windows form, it must first be added to the Toolbox.  
  1. Open the Components panel of the Toolbox:

  1. Right-click on a blank part of the Components panel and select "Add/Remove Items..." from the drop-down menu:

  1. Click the "Browse..." button in the Customize Toolbox dialog:

  1. Select the edtFTPnet DLL from the file dialog and press "Open":

  1. Click OK in the Customize Toolbox dialog and you should now see that FTPConnection has been added to your Components Toolbox panel:

2. Adding an FTPConnection to a Windows Form

Create a new Windows Form and drag an FTPConnection onto the form.  Since the component is not a visible control, an icon representing it will appear below the form itself:

3. Setting FTPConnection Properties

Set the FTPConnection properties as shown below:

4. Placing Controls on the Form

Place a button and a listbox on the form as shown below:

5. Making Things Happen

  1. Double-click on button1 to create an event-handler for it.
        private void button1_Click(object sender, System.EventArgs e)
        {
       
        }
  1. Place code as follows into the event-handler:
        private void button1_Click(object sender, System.EventArgs e)
        {
            ftpConnection1.Connect();
            string[] files = ftpConnection1.GetFiles();
            listBox1.Items.AddRange(files);
            ftpConnection1.Close();
        }
  1. Run the application and press the button.  You should now see a list of files in the list-box:

Troubleshooting

Common sources of problems are:
  1. Incorrect server address set (i.e. the RemoteHost property of FTPConnection).
  2. Incorrect user-name or password (i.e. the UserName and Password properties of FTPConnection).
  3. No files on the server.  If nothing seems to happen when the button is pressed, it may be simply because there are no files in the user's directory on the server.
  4. For other problems you may refer to the EDT forums.