[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

.net (vb or c#) file transfer problems

Posted on 2007-11-30
3
Medium Priority
?
219 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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 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