Solved

.net (vb or c#) file transfer problems

Posted on 2007-11-30
3
214 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 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