Problems getting FTP response after successful request

K

K Viltersten

I'm uploading a file to a FTP-server and after
the download, which is successful, since i see
the file as it's supposed to be, i'd like to
check on the response left by the server.

The problem is that when i execute

upload.GetResponse();

i'm getting an error message about saying that
the connection is in use and that i can't
perform a new call.

I have no clue on how to approach it. Please
suggest what might be wrong here.



FtpWebRequest upload =
(FtpWebRequest) WebRequest.Create( uri );
upload.Method = WebRequestMethods.Ftp.UploadFile;
upload.UseBinary = true;

FileStream fs = new FileStream( local, FileMode.Open );
BinaryReader reader = new BinaryReader( fs );
byte[] dataRead = new byte[fileInfo.Length];
reader.Read( dataRead, 0, dataRead.Length );
reader.Close();
fileStream.Close();

Stream stream = upload.GetRequestStream();
foreach (byte b in dataRead)
stream.WriteByte( b );

FtpWebResponse response =
(FtpWebResponse) upload.GetResponse();
if (response.StatusDescription.StartsWith( "226" )) {}
 
M

Martin Honnen

K said:
I'm uploading a file to a FTP-server and after
the download, which is successful, since i see
the file as it's supposed to be, i'd like to
check on the response left by the server.

The problem is that when i execute

upload.GetResponse();

i'm getting an error message about saying that
the connection is in use and that i can't
perform a new call.

I have no clue on how to approach it. Please
suggest what might be wrong here.
Stream stream = upload.GetRequestStream();
foreach (byte b in dataRead)
stream.WriteByte( b );

Try whether
stream.Close();
here before you access the response helps.
And of course writing the request byte by byte is rather inefficient.
That is not the cause of your current problem but I would change the
code to use e.g.
stream.Write(dataRead, 0, dataRead.Length);
 
K

K Viltersten

I'm uploading a file to a FTP-server and after
Try whether
stream.Close();
here before you access the response helps.

Yes, it does. Thanks!
And of course writing the request byte by
byte is rather inefficient. That is not
the cause of your current problem but I
would change the code to use e.g.
stream.Write(dataRead, 0, dataRead.Length);

I thought so too but intellisense gave me
something along the lines of "in derived
class it will do this and that", so i
assumed it was implementable but not very
well implemented.

Yes, i do agree it's very unefficient and
should be avoided. Thanks for pointing out
additional improvement opportunities,
besides the original question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top