Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
15.8k views
in .NET FTP by (320 points)
Does anyone know how to capture the logging info coming from the FTP server? I can see it in the debug window in Visual Studio, but do not know how to capture it. I would like to post it to a listbox in my program.

11 Answers

0 votes
by (161k points)
Some of the constructors allow you to pass a StreamWriter as a parameter, which will capture the output.

Does anyone know how to capture the logging info coming from the FTP server? I can see it in the debug window in Visual Studio, but do not know how to capture it. I would like to post it to a listbox in my program.
0 votes
by (320 points)
I'm having a lot of trouble getting the StreamWriter to work. All I want to do is initialize it and write the text to a TextBox...
0 votes
by (161k points)
Can you post a small code fragment showing what you are doing?

I'm having a lot of trouble getting the StreamWriter to work. All I want to do is initialize it and write the text to a TextBox...
0 votes
by (320 points)
Thanks for your help!

In my Form1 Class the StreamWriter is declared like this:
private System.IO.StreamWriter logWriter;

later on is this function:
private void connectButton_Click(object sender, System.EventArgs e)
{
String host = this.hostTextBox.Text;
int port = Convert.ToInt32(this.portTextBox.Text);
DirectoryInfo localDirectory;

try
{
//connect to client
client = new FTPClient(host, logWriter, port);
logIt();

//turn on debugging
client.DebugResponses(true);

//login in to client
client.Login(userTextBox.Text, passTextBox.Text);
logIt();

//Get remote directory
remoteDirTextBox.Text = client.Pwd();
logIt();

//Populate Remote ListBox
remoteDirListBox.Items.AddRange(client.Dir());
logIt();

//Poputlate Local ListBox
localDirectory = new DirectoryInfo(localDirTextBox.Text);
localDirListBox.Items.AddRange(localDirectory.GetDirectories());
localDirListBox.Items.AddRange(localDirectory.GetFiles());


}
catch(Exception errorCode)
{
catchBox.Text = errorCode.Message;
}

}

The LogIt() function is this:
private void logIt()
{
logBox.Text += logWriter.ToString();
logWriter.Flush();
}
0 votes
by (161k points)
Where do you instantiate the StreamWriter?
0 votes
by (320 points)
I instantiate the StreamWriter in the form constructor after IntializeComponent() like this.

this.logWriter = new StreamWriter("log.txt");
0 votes
by (161k points)
You seem to be doing everything correctly - I can't see what the problem is. Try running through the VS debugger and see if you can see what is going on - you have our source.

I don't think we can really help without experimenting with your source ourselves.

I instantiate the StreamWriter in the form constructor after IntializeComponent() like this.

this.logWriter = new StreamWriter("log.txt");
0 votes
by (320 points)
Apparently "log.txt" is being written correctly. I just viewed it in notepad and can see the info from my last connection. The problem i have is that i would like to access the log information on the fly at runtime and load it into a text box. Is there any way for me to do that without opening a streamreader on "log.txt" and reading it from there?
0 votes
by (161k points)
You could create a MemoryStream and pass it to the StreamWriter constructor - then everything should be stored in memory rather than in a file, and you can retrieve it.

This does make me think we should change the parameter to TextWriter, so a StringWriter can be supplied - might be neater.

Apparently "log.txt" is being written correctly. I just viewed it in notepad and can see the info from my last connection. The problem i have is that i would like to access the log information on the fly at runtime and load it into a text box. Is there any way for me to do that without opening a streamreader on "log.txt" and reading it from there?
0 votes
by (320 points)
So I pass the StringWriter constructor a MemoryStream, but how can i now read from it? I keep getting an exception thrown. here is my code...

private System.IO.StreamWriter logWriter;
private System.IO.StreamReader logReader;
private System.IO.MemoryStream memStream;

MemoryStream memStream = new MemoryStream();
this.logWriter = new StreamWriter(memStream);
this.logReader = new StreamReader(memStream);

private void logIt()
{
logBox.Text = FromASCIIByteArray(memStream.ToArray());

}

public static string FromASCIIByteArray(byte[] characters)
{
ASCIIEncoding encoding = new ASCIIEncoding( );
string constructedString = encoding.GetString(characters);

return (constructedString);
}

Categories

...