VB file transfer

Microsoft Visual studio 2008 professiona...
March 17, 2010 at 11:57:29
Specs: Windows XP
Hi everyone,

I need help in writing code for sending files using socket programming in vb 2005.

I have enabled text transfer through socket stream, i want file transfer to take place between remote pc's connected via sockets.. can somebody help me with this.

If file transfer is not possible via sockets.. is their an alternate way of doing it.. ?



See More: VB file transfer

Report •

March 17, 2010 at 15:56:48
you might find some help here, looks like a lot of folks doing the same kinda stuff:
This, and google "winsock methods properties" is where i am going to try and learn how to implement with the tools i do have. It should not be hard at all:
get user input (filename etc)
open the socket, chunk the file into x-size pieces, send out the port (socket).
I can't help using your vb code cause i don't have vb 2005.
when i open it, lots of red lines, all pertaining to socket object.

Report •

March 20, 2010 at 21:15:14
I worked with it some, finally got the mswinsck.oca to work going from the tutorial mentioned above.
I got it to transfer a binary file like this:
open file.com for binary access read as #1
do while not eof(1)
if qq=q then exit do
tcpserver.senddata x
close #1
'---------- end
the doevents seems to be required.
the loop should exit before the end of file, but for some
reason it does not. a better way might be to error-trap
the end-of-file, to ensure that the complete binary is transmitted in full.
it's not the speediest car on the block, but it worked.
i tested the .com file on the receiver and it ran as it should.
i had to use netcat as the "catcher" on my XP because some stupid "you don't have license to use mswinsck". (!?!)
I need to figure out how to get that fixed!
If you want my complete code i can pmail or email it to you.

Report •

March 22, 2010 at 15:04:45
Hi x-techkid,

i said previously that i would send you the code that i have in my application to send files, however i wrote this to send only text files, its not the best method but i worked for what i needed it for, i got some help online but i cannot find the link i used, it was a few years back now, anyways i hope this helps im not sure how it will display when i copy paste it, if you want the app i wrote (test version) i would be more than happy to email it to anyone that wants it..


Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
'When data is recived we must first identify what type of data it is.
End Sub

Private Sub CheckDataType()
'there are two types of data that can be recivied a file, or an error message.

Winsock1.GetData TheData

If Left(TheData, 6) = "Error:" Then
MsgBox TheData
Exit Sub
Recivedata App.Path & "\" & Text2.Text & ".txt", TheData
End If

End Sub

'this is used by the DataAlrrival in the previous form
Public Sub Recivedata(FileNametoSave As String, Data)

FreeFileNumber = FreeFile ' assigsn a filenumber to YOUR file
'Winsock1.GetData Data
'Check to see if the file is already open
Open FileNametoSave For Binary Access Write As #FreeFileNumber
'transfer data to another variable to be manipulated

temp = Data

'Check to see if it is the end of the transmition
'If it is the end, it will close the file
'You may also add different cases here for under functions
If temp = "end" Then
FileRequest = False
Close #FreeFileNumber
CheckFileAva = False
MsgBox "Transfer Success"
OpenRecivedFile FileNametoSave
Put #FreeFileNumber, , temp
End If

End Sub

Private Sub Winsock1_DataArrival(index As Integer, ByVal bytesTotal As Long)
'server ONLY accepts the clients computer name (which must begin with "Name")
'AND the log file but only if it was requested.

Dim TheData As String

Winsock1(index).GetData TheData
ClientIndex = index 'This identifies WHO requested the file.
FileRequested = (TheData & ".txt")
SearchFile (FileRequested)

End Sub

Private Sub SearchFile(FileName As String)
'This function recivies that filename as a argument and then searches it current
'directory to see it that file exists.
'if not then an error report is send else the file is sent.

Dim FileSystem, FindFile

Set FileSystem = CreateObject("Scripting.FileSystemObject")
FindFile = FileSystem.FileExists(App.Path & "\" & FileName)

If FindFile = True Then
SendFile (App.Path & "\" & FileName)
If FindFile = False Then
End If
End If
End Sub

I hope this is enough for you to understand what i was doing, basically the client and server must establish a connection a you know, multiple clients can connect to the server, when a client requests a file the server will check who requested it and send the file, one thing to note is that in some of my apps what i do is prefix the request with a symbol or a sequence so that when the server recieves the request it can determine what the client is asking.

Hope this helps.


Report •

Related Solutions

March 25, 2010 at 03:23:06
Hi AlwaysWillingtoLearn and Nbrane,

Thanks a lot .. ive tried implementing both concepts .. Ive threaded the file sending code for socket it seems to work fine , but am looking to encryp-decryp the file in transist can u guys suggest better encryption algorithm..at file level..!!

Thanks in Advance


Report •

March 25, 2010 at 04:35:12
I have a very basic file encryption program that i wrote a while ago, basically its just a replaces eah charector with its corresponding ascii value, not a great way to encrypt but i guess it worked for what i needed it for and well it should be a start for you.

Will post the code later when i get home..

Just curious what is it you are developing sound interesting?

Report •

March 25, 2010 at 20:01:14
I wrote one that's also quite simple, reverses the order of the bytes and reverses the bytes (newbyte=255-byte).
another method would be to reverse every n bytes where n
is any random number:
for i=0 to lof(1)/n
for j=n to 1 step -1
get #1,i*10+j,a
put #2,,a
next j
next i
'--------- end
f/e: if n is 4 and file has "testing", output is
but also reverse the byte-values as well, which could
also be random-based instead of 255. the keys would
be the two random numbers.
But why not kill two mosquitos with one swat: compress the file with encryption option (all the compressors, even good old pkzip, offer encryption+password) for better encryptioning?
ps: have you tried to tackle telnet yet? I'm trying to train mine to negotiate telnet protocol, and having a bitch of it. I've googled the protocols and sent the right junk, but i can't get past the negotiation junk. it just sits there. If you've managed this, i would appreciate any pointers you can give me. I downloaded a telnet-server for windows which i'm going to use to see if i can decipher what it wants that i'm (my program that is ) not giving it.

Report •

Ask Question