|
-
Apr 8th, 2001, 03:28 PM
#1
Thread Starter
Hyperactive Member
Hrmmmmm... Here's the deal. I made a connection (using client to server software I programmed) on port 1000 with winsock. I'm trying to make my client send a file to the server. Sending text is simple but sending files is proving more difficult. Can someone give me an example that works for sending files with winsock and explains what is going on? I've seen code before but I can't figure it out because they came with no instructions. I want to understand how to do things and program it myself then, not steal it.
-
Apr 8th, 2001, 07:44 PM
#2
Member
zer0_flaw,
Hrmmmmm..... Well it appears that it is easier to find file's than article's on this subject, but I'll give it a whorl. The last one on the bottom is the search engine that I used.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TCP/IP through calls to WINSOCK.DLL
http://david90.freeservers.com/tutorial/tcp.htm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
How to use Winsock Control in order to build Internet applications
http://www.vbip.com/winsock/winsock_control.asp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CFtpConnection Class Reference
http://www.vbip.com/winsock/winsock_ftpclass_ref.asp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FTP Quick Reference
http://www.vbip.com/winsock/winsock_ftp_ref_03.htm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
General Information
http://www.vbip.com/winsock/index.asp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Secrets of FTP
http://www.vbip.com/winsock/winsock_ftp_01.asp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Winsock file transfer
http://www.vb-world.net/demos/winsock/index.html
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WinSock Development Information
http://www.sockets.com/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VB Winsock Programming Source and Examples
http://www.acky.net/vb/vbtcp/index2.sht
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Search Engine used: Codehound
http://www.codehound.com/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hope this helps.
Jerome W. Norgren
"Know how to ask. There is nothing more difficult for some people, nor for others, easier."
- Baltasar Gracian
-
Apr 8th, 2001, 07:53 PM
#3
Addicted Member
At first you should send the size of the file to the remote-site. After you've done this, just send the content of the file...
-- Client --
Code:
Dim SendComplete As Boolean
Private Sub Command1()
'the connection must exist...
Dim Path As String
Path = "C:\blabla.txt"
Winsock1.SendData CStr(FileLen(Path))
'Wait until the remote-site received the size
Do While SendComplete = False
DoEvents
Loop
Dim Buffer() As Byte
'Then send the files content
Open Path For Binary Access Read As #1
ReDim Buffer(0 To LOF(1)-1)
Get #1, , Buffer()
Winsock1.SendData Buffer()
Close #1
'The part above sends the whole file at once.
'When the file's size is really big... You'll have
'to send it in parts... ;)
End Sub
Private Sub Winsock1_SendComplete()
SendComplete = True
End Sub
-- Remote --
Code:
Dim ReceivedLength As Boolean
Dim LengthOfFile As Long
Dim BytesReceived As Long
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
If ReceivedLength = False Then
Dim lData As String
Winsock1.GetData lData, vbString
'The length of the file
LengthOfFile = CLng(lData)
'Set ReceivedCounter to Zero
BytesReceived = 0
'So we know that we've received the size
'to receive the content of the file next
ReceivedLength = True
Dim Path As String
Path = "C:\blabla.txt"
'Create the file if it doesn't exist or
'clear it if it does...
Open Path For Output As #1: Close #1
'Open for binary
Open Path For Binary Access Write As #1
Else
Dim data() As Byte
ReDim data(0 To bytesTotal - 1)
BytesReceived = BytesReceived + bytesTotal
Winsock1.GetData data
Put #1, , data
'When the amount of received bytes is equal
'to the length of the file we've done
If BytesReceived >= LengthOfFile Then
Close #1
'do some handling stuff...
End If
End If
End Sub
Hope this helps,
Dennis.
When you need further explanations just ask me.
Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?
Originally posted by aknisely
Sorry, but I feel uncomfortable on CC with clothes on
__________________
The truth ... is out there!
-
Aug 8th, 2005, 04:50 PM
#4
Hyperactive Member
VB App and XP feel
how can i make my VB Apps have XP feel, the buttons, option an d check boxes etc
thanx
oyad
Nobody is smarter than all of us!
-
Aug 8th, 2005, 05:56 PM
#5
Re: Help on sending files with winsock.
What does that have to do with "Help on sending files with winsock" ? You do know how to create a thread right? You practically bumped a very old thread and provided your own title for your post.
Anyways here how:
http://www.planet-source-code.com/vb...60550&lngWId=1
http://www.planet-source-code.com/vb...52071&lngWId=1
-
Aug 8th, 2005, 05:58 PM
#6
Re: Help on sending files with winsock.
dmr, What do you think will happen if the file size I wanna send is.... say... 10 GBytes, using your code ?
zer0_flaw, You should use the code I posted here to send properly files, especially use it for large files.
-
Aug 8th, 2005, 05:59 PM
#7
Re: Help on sending files with winsock.
Woops... I did not even notice this thread is SOOOOO OLLLDDDD
-
Aug 8th, 2005, 06:43 PM
#8
Re: Help on sending files with winsock.
Look into post #4. It has nothing to do with this thread apparently.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|