473,378 Members | 1,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Binary tranfer using TCPStream

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

Nov 16 '05 #1
2 1736
redneon <re*****@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
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,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"redneon" <re*****@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
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

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: build | last post by:
G'day All, I'm trying to code a "Data Downloader" to automatically login and download data from www.Investorweb.com.au using the Internet Transfer Control. I have a some VB experience but no...
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
11
by: ajou_king | last post by:
I was running some tests on my Win32 1GHZ processor to see how long it would take to transmit objects numerous times via TCP/IP using C# ..NET Remoting vs the C++ trustworthy method of binary...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
1
by: Philip Wagenaar | last post by:
I have a server (tcp/ip) that receives and sends back XML. When I use the following code to send a login xml string my application hangs. I think it is waiting for somekind of notification that...
0
by: fabrice | last post by:
Hello, I have got a little problem with Url Rewritig process and server.transfer use. I would like to create a simple url rewriting process for my web site I use in a lot of pages, the...
3
by: shahla.saeed | last post by:
hi, plzz check my code and let me know where the problem is lying...becuase whenever i try to tansfer the file of 573KB(mp3) it just tranfer few Kb of file(Somtimes 5.2Kb,somtimes 32Kb..every time...
2
by: Dale Harris | last post by:
Hi, I was wondering, is there a difference between Server.Transfer and Response.Redirect? They seem to do the same thing. Or am I mistaken? TIA ** Posted from http://www.teranews.com **
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.