Vb 2005 - file transfer..

March 2, 2010 at 05:45:20
Specs: Windows XP
Hi

I need help in developing an application in Visual basic 2005 for file transfer between two computers.. there is a server program.. and two client applications..
Communication between them takes place via sockets.. they can send and receive text messages through streams.. but i would like to add file transfering capabilites to these application..

Could some one help me with it.. may be winsock programming..

Please help me with this, am tryin to figure out a way for the past one month :(

Regards

X-Techkid



See More: Vb 2005 - file transfer..

Report •


#1
March 2, 2010 at 13:23:52
If you have capability of opening and communicating to any given socket, you just need socket #21 and use native ftp commands. Those commands are listed when you do:
c:>ftp -n -s:login
ftp>remotehelp

If you need to see how they're used, either google for "ftp commands" or set debug on in your ftp session, perform various commands and see what ftp puts on screen.
f/e:
ftp>debug on
ftp>get a.htm
---> RETR a.htm

this tells you that RETR is the command to RETRieve a file.

I would be interested to see your vb code for opening and communicating to a socket, this is something i've been wanting to learn about. I've been using NETCAT (NC.EXE) to access sockets, but i would like to write my own.


Report •

#2
March 2, 2010 at 22:12:55
Hi nbarne

Thanks for the reply, i would try that for sure !!

here is ma code.. ive posted below few routines in ma code..

Server routines..

Module Module1
Dim clientsList As New Hashtable
Sub Main()
Dim serverSocket As New TcpListener(8888)
Dim clientSocket As TcpClient
Dim infiniteCounter As Integer
Dim counter As Integer
msg("Please Wait Server Is starting ...")
serverSocket.Start()
msg("Chat Server Started ....")
counter = 0
infiniteCounter = 0
For infiniteCounter = 1 To 2
infiniteCounter = 1
counter += 1
clientSocket = serverSocket.AcceptTcpClient()

Dim bytesFrom(10024) As Byte
Dim dataFromClient As String

Dim networkStream As NetworkStream = _
clientSocket.GetStream()
networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom)
dataFromClient = _
dataFromClient.Substring(0, dataFromClient.IndexOf("$"))

clientsList(dataFromClient) = clientSocket

broadcast(dataFromClient + " Joined ", dataFromClient, False)

msg(dataFromClient + " Joined chat room ")
Dim client As New handleClient
client.startClient(clientSocket, dataFromClient, clientsList)
Next
clientSocket.Close()
serverSocket.Stop()
msg("exit")
Console.ReadLine()
End Sub


Sub msg(ByVal mesg As String)
mesg.Trim()
Console.WriteLine(" >> " + mesg)
End Sub


Private Sub broadcast(ByVal msg As String, _
ByVal uName As String, ByVal flag As Boolean)
Dim Item As DictionaryEntry
For Each Item In clientsList
Dim broadcastSocket As TcpClient
broadcastSocket = CType(Item.Value, TcpClient)
Dim broadcastStream As NetworkStream = _
broadcastSocket.GetStream()
Dim broadcastBytes As [Byte]()
If flag = True Then
broadcastBytes = Encoding.ASCII.GetBytes(uName + " says : " + msg)
Else
broadcastBytes = Encoding.ASCII.GetBytes(msg)
End If
broadcastStream.Write(broadcastBytes, 0, broadcastBytes.Length)
broadcastStream.Flush()
Next
End Sub


Public Sub startClient(ByVal inClientSocket As TcpClient, _
ByVal clineNo As String, ByVal cList As Hashtable)
Me.clientSocket = inClientSocket
Me.clNo = clineNo
Me.clientsList = cList
Dim ctThread As Threading.Thread = New Threading.Thread(AddressOf doChat)
ctThread.Start()
End Sub


Private Sub doChat()
Dim infiniteCounter As Integer
Dim requestCount As Integer
Dim bytesFrom(10024) As Byte
Dim dataFromClient As String
Dim sendBytes As [Byte]()
Dim serverResponse As String
Dim rCount As String
requestCount = 0
For infiniteCounter = 1 To 2
infiniteCounter = 1
Try
requestCount = requestCount + 1
Dim networkStream As NetworkStream = _
clientSocket.GetStream()
networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom)
dataFromClient = _
dataFromClient.Substring(0, dataFromClient.IndexOf("$"))
msg("From client - " + clNo + " : " + dataFromClient)
rCount = Convert.ToString(requestCount)
broadcast(dataFromClient, clNo, True)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Next
End Sub
end module1


Client application routine's

Private Sub msg()
If Me.InvokeRequired Then
Me.Invoke(New MethodInvoker(AddressOf msg))
Else
ListBox1.Items.Add(readData)
ListBox1.SelectedIndex = ListBox1.Items.Count – 1
speechwork(readData)
connectbox.Visible = False
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
connectbox.Visible = True
readData = "Conected to Chat Server ..."
msg()
My.Computer.Audio.Play(My.Resources.ButtonClicked, AudioPlayMode.Background)
Dim ipaddress As String
ipaddress = iptext.Text
clientSocket.Connect(ipaddress, 8888)
'Label1.Text = "Client Socket Program - Server Connected ..."
serverStream = clientSocket.GetStream()
Dim outStream As Byte() = _
System.Text.Encoding.ASCII.GetBytes(TextBox3.Text + "$")
serverStream.Write(outStream, 0, outStream.Length)
serverStream.Flush()
Dim ctThread As Threading.Thread = New Threading.Thread(AddressOf getMessage)
ctThread.Start()
End Sub


Private Sub getMessage()
For infiniteCounter = 1 To 2
infiniteCounter = 1
serverStream = clientSocket.GetStream()
Dim buffSize As Integer
Dim inStream(10024) As Byte
buffSize = clientSocket.ReceiveBufferSize
serverStream.Read(inStream, 0, buffSize)
Dim returndata As String = _
System.Text.Encoding.ASCII.GetString(inStream)
readData = "" + returndata
msg()
Next
End sub


Report •

#3
March 2, 2010 at 22:20:55
thanks! this gives me something to study and work with.
I am very un-knowledgable in all aspects, this will help me.

Report •
Related Solutions


Ask Question