VB icon

a Send / Get files using winsock

Submitted on: 1/4/2015 7:00:00 AM
By: Dustin Davis (from psc cd)  
Level: Advanced
User Rating: By 13 Users
Compatibility: VB 5.0, VB 6.0
Views: 994
     Want your program to be able to send and get files over the internet? Well, here you go! This is very easy to understand.
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
' Name: a Send / Get files using winsock
' Description:Want your program to be able to send and get files over the internet? Well, here you go! This is very easy to understand.
' By: Dustin Davis (from psc cd)

'Note: This is a custom control for your applications. This will not properly
'Get files from the internet or from an ftp. Although the dataarival sub would
'be the same, I do not know how the transition would end so I just sent "xx"
'and that tells the sub that the transition has ended
'Public declarations
dim FileOpen as Boolean
public function Send_File(FileToSend as string)
'This is the function that sends a file
Dim Temp as string
Dim BlockSize as long
open filetosend for binary access read as #1 'Open the file to send
BlockSize = 2048 'Set the block size, if needed, set it higher
do while not EOF(1)
 temp = Space$(blockSize) 'Give temp some space to store the data
 Get 1, , temp 'Get first line from file
 Winsock1.SendData temp 'Send the data
winsock1.senddata "xx" 'This is a custom control that ends the transmition
close #1
end function
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim temp As String
Dim data As String
'Check to see if the file is already open
If fileOpen = False Then
 Open "c:\somefile_here" For Binary Access Write As #2
 fileOpen = True
ElseIf fileOpen = True Then
End If
Winsock1.GetData data 'Get the data
temp = data
'Check to see if it is the end of the transmition
If temp = "xx" Then
 Close #2
 fileOpen = False
Put 2, , temp 'Store the data to the file
End If
End Sub

Other 16 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.