Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
4.5k views
in .NET FTP by (220 points)
I tried the following and got an exception at the marked line. Any ideas? Documentation for this function would be a Good Thing.

ftpConnection1.ServerAddress = "...";
ftpConnection1.UserName = "...";
ftpConnection1.Password = "...";
ftpConnection1.Connect();

byte[] b = Encoding.ASCII.GetBytes("Hello, world!\n");
MemoryStream m = new MemoryStream(b);
ftpConnection1.UploadStream(m, "test.txt"); // ** Exception

ftpConnection1.Close();


The exception was:

An unhandled exception of type 'System.ObjectDisposedException' occurred in mscorlib.dll

Additional information: Cannot access a closed Stream.

What am I doing wrong?

5 Answers

0 votes
by (220 points)
If it helps: I looked at the source for FTPConnection.cs, and the problem seems to be that the call to FTPClient.Put inside UploadStream closes its stream as a side-effect, and then the OnUploaded(stream ...) event calls srcStream.Length, which is at that point invalid. This explains the error but it's a mystery to me why the stream gets closed. Try adding an Uploaded event handler to the above, and you'll presumably see the problem in operation.
0 votes
by
Thanks again for reporting the problem. FTPConnection is a class that has only recently been added to edtFTPnet, so its quality is not as high as the rest of the library. We will fix this bug as soon as we can.

- Hans (EDT)
0 votes
by (220 points)
I've worked around it, and in the process learned a bit of how the whole thing works, so it's not a total loss. I now have a program that generates an XML document and uploads it to my server, and all without me typing a single angle bracket or coding a buggy piece of asynchronous RFC-wotsit code, so I'm pretty happy.

Definitely need to do something about that doco though. How do I set up VS2003 so I'm running the actual compiled-from-source version of your component instead of the pre-compiled DLL? I'd be happy to fill in some gaps in the NDoc stuff (teaching myself the format as I go) and send the diffs. That's what F/OSS is about, after all!
0 votes
by
is this bug been fixed?
0 votes
by (51.6k points)
Yes, this has been fixed in the version that is due to be released in the next week or so.

- Hans (EDT)

Categories

...