Binary tranfer using TCPStream

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm writing a small FTP client to include in one of my programs but I'm not
sure how to get a binary stream using the TCPStream. This is my code at the
moment...

responseConnection = new TcpClient(responseIP, responsePort);
responseStream = responseConnection.GetStream();
responseReader = new StreamReader(responseStream);
StreamWriter fileStream = new StreamWriter(@"C:\" +
lstFTPView.SelectedItems[0].Text, false);

do
{
output = responseReader.ReadLine();
if (output != null)
{
fileStream.WriteLine(output);
} while(output != null);

The problem with the above is that it reams the stream text but this wont
work with binary files. How can I get around this?

Thanks,

Darrell
 
redneon said:
I'm writing a small FTP client to include in one of my programs but I'm not
sure how to get a binary stream using the TCPStream. This is my code at the
moment...

responseConnection = new TcpClient(responseIP, responsePort);
responseStream = responseConnection.GetStream();
responseReader = new StreamReader(responseStream);

That's the problem to start with. If you've got binary data, you don't
want to use a StreamReader and StreamWriter. Just use the response
stream, and write to a file stream.
 
Hi,

Just use a FileStream to write the data to.
a NetworkStream is a binary stream already so all you have to do is use
another binary stream to write the data to.

Cheers,
 
Back
Top