Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
2.4k views
in .NET FTP by (160 points)
Im novice in .NET and I hope you help me.
I use edtftpnet-1.2.2 (freeware)

I need output all server messages in listbox.
I want to use events ReplyReceived and CommandSent.
Look at my code.

// ftpConnection1
// 
this.ftpConnection1.AutoLogin = true;
this.ftpConnection1.ConnectMode = EnterpriseDT.Net.Ftp.FTPConnectMode.PASV;
this.ftpConnection1.DeleteOnFailure = true;
this.ftpConnection1.EventsEnabled = true;
this.ftpConnection1.ParsingCulture = new System.Globalization.CultureInfo("");
this.ftpConnection1.Password = null;
this.ftpConnection1.ServerAddress = null;
this.ftpConnection1.ServerPort = 21;
this.ftpConnection1.StrictReturnCodes = true;
this.ftpConnection1.Timeout = 0;
this.ftpConnection1.TransferBufferSize = 4096;
this.ftpConnection1.TransferNotifyInterval = ((long)(4096));
this.ftpConnection1.TransferType = EnterpriseDT.Net.Ftp.FTPTransferType.BINARY;
this.ftpConnection1.UserName = null;
this.ftpConnection1.ReplyReceived += new EnterpriseDT.Net.Ftp.FTPMessageHandler(this.ftpConnection1_ReplyReceived);
this.ftpConnection1.CommandSent += new EnterpriseDT.Net.Ftp.FTPMessageHandler(this.ftpConnection1_CommandSent);
...
private void ftpConnection1_CommandSent(object sender, EnterpriseDT.Net.Ftp.FTPMessageEventArgs e)
{
   listBox1.Items.Add(e.Message.ToString());
}

private void ftpConnection1_ReplyReceived(object sender, EnterpriseDT.Net.Ftp.FTPMessageEventArgs e)
{
   listBox1.Items.Add(e.Message.ToString());
}


I put breakpoint in ftpConnection1_CommandSent() and ftpConnection1_ReplyReceived()
I complitly download file but this events dont work.
Whats problem?

2 Answers

0 votes
by (51.6k points)
Please try this application:
public class TestForm : System.Windows.Forms.Form
{
   private EnterpriseDT.Net.Ftp.FTPConnection ftpConnection1;
   private System.Windows.Forms.ListBox fileListBox;
   private System.Windows.Forms.ListBox commandListBox;
   private System.ComponentModel.IContainer components;

   public TestForm()
   {
      InitializeComponent();
   }

   private void TestForm_Load(object sender, System.EventArgs e)
   {
      ftpConnection1.ServerAddress = "ftp.microsoft.com";
      ftpConnection1.UserName = "anonymous";
      ftpConnection1.Password = "test@test.com";
      ftpConnection1.Connect();
      fileListBox.Items.AddRange(ftpConnection1.GetFiles());
      ftpConnection1.Close();
   }

   private void ftpConnection1_CommandSent(object sender, EnterpriseDT.Net.Ftp.FTPMessageEventArgs e)
   {
      commandListBox.Items.Add(e.Message);
   }

   private void ftpConnection1_ReplyReceived(object sender, EnterpriseDT.Net.Ftp.FTPMessageEventArgs e)
   {
      commandListBox.Items.Add(e.Message);
   }

   #region Windows Form Designer generated code
   private void InitializeComponent()
   {
      this.components = new System.ComponentModel.Container();
      this.ftpConnection1 = new EnterpriseDT.Net.Ftp.FTPConnection(this.components);
      this.fileListBox = new System.Windows.Forms.ListBox();
      this.commandListBox = new System.Windows.Forms.ListBox();
      this.SuspendLayout();
      // 
      // ftpConnection1
      // 
      this.ftpConnection1.ReplyReceived += new EnterpriseDT.Net.Ftp.FTPMessageHandler(this.ftpConnection1_ReplyReceived);
      this.ftpConnection1.CommandSent += new EnterpriseDT.Net.Ftp.FTPMessageHandler(this.ftpConnection1_CommandSent);
      // 
      // fileListBox
      // 
      this.fileListBox.Location = new System.Drawing.Point(8, 8);
      this.fileListBox.Name = "fileListBox";
      this.fileListBox.Size = new System.Drawing.Size(264, 95);
      this.fileListBox.TabIndex = 1;
      // 
      // commandListBox
      // 
      this.commandListBox.Location = new System.Drawing.Point(8, 112);
      this.commandListBox.Name = "commandListBox";
      this.commandListBox.Size = new System.Drawing.Size(264, 95);
      this.commandListBox.TabIndex = 2;
      // 
      // TestForm
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(280, 214);
      this.Controls.Add(this.commandListBox);
      this.Controls.Add(this.fileListBox);
      this.Name = "TestForm";
      this.Text = "TestForm";
      this.Load += new System.EventHandler(this.TestForm_Load);
      this.ResumeLayout(false);

   }
   #endregion

   [System.STAThread]
   static void Main() 
   {
      System.Windows.Forms.Application.Run(new TestForm());
   }
}

The application has two list-boxes: one for the directory listing and one for the commands.

It works fine on my machine. Please let me know if it works on yours.

- Hans (EDT)
0 votes
by (160 points)
Thanks for help. I find my mistake. (stupid mitake :)
This class is really very well work.

Categories

...