Solved

.net (vb or c#) file transfer problems

Posted on 2007-11-30
3
212 Views
Last Modified: 2013-12-16
Here is the paste bin of my code: http://pastebin.com/m5b4d4d85

Here is the problem:
1 - im trying to make it so I can transfer large files. I have it now to the point it "thinks" its sending the large file but its always corrupt do to sending to many bytes. It seems when I change the "Dim blocksize As Int16 = 1000" to a different number such as 8000 it either gets it closer to the right file size or farther away if that makes sense. So have to figure out why its doing that.

2 - testing on a small file 1kb zip file. When it transfers it, I can open it up and view my text file inside the zip and everything works fine except that the transfered zip is now 3kb not 1kb like the original. So have to figure this out as well dont make sense to me.

Im new to this networking stuff so bare with me as this code is probably "gross" but any help would be greatly appreciated.

Thank You!
0
Comment
Question by:aumudin
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
ID: 20388093
Here is your problem:

thisread = fileStream.Read(dataByte, 0, blocksize)
networkStream.Write(dataByte, 0, dataByte.Length)

The Read method returns the number of bytes read. You ignore this value and just write the entire content of the buffer regardless of how much of the buffer was actually used.

Change if to only write the actual data that you got:

thisread = fileStream.Read(dataByte, 0, blocksize)
If thisread > 0 Then
   networkStream.Write(dataByte, 0, thisread)
End If
0
 
LVL 4

Author Comment

by:aumudin
ID: 20388167
Perfect! Thank you very much
0
 
LVL 4

Author Closing Comment

by:aumudin
ID: 31412078
TY
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem to error 4 45
Vb.net dynamic formulas in runtime 11 62
Name space syntax error 12 43
Resolve Dependency Issues 4 47
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now