1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Network File Transfer vb.net

Discussion in 'Programming & Webmastering' started by shuggans, Dec 27, 2011.

  1. shuggans

    Joined:
    Dec 22, 2007
    Messages:
    175 (0.07/day)
    Thanks Received:
    7
    Location:
    Central Nebraska
    Hello all. I'm developing an application that automatically sends files from a machine running the client app to a server running the server app. The files in question are very large files, (500mb - 2GB in size) and I was wondering what is the best way to transfer them qucikly and efficiently over the network. Should I utilize FTP transfer, or should I develop a TCP transfer client/server?

    If TCP, can anybody give me a basic run down of the networkstream class used with the tcplistener? Thanks guys.
     
  2. DanTheBanjoman Señor Moderator

    Joined:
    May 20, 2004
    Messages:
    10,553 (2.77/day)
    Thanks Received:
    1,383
    Assuming the network means LAN I'd simply use the File.Copy method on a network share.
     
  3. shuggans

    Joined:
    Dec 22, 2007
    Messages:
    175 (0.07/day)
    Thanks Received:
    7
    Location:
    Central Nebraska
    Network shares are out of the question for my purposes
     
  4. DanTheBanjoman Señor Moderator

    Joined:
    May 20, 2004
    Messages:
    10,553 (2.77/day)
    Thanks Received:
    1,383
    Since you have to run an application on both the server and the client. You could simply install a simple http/ftp server and use webclient from the server to download the files.
     
  5. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,796 (6.26/day)
    Thanks Received:
    3,678
    Location:
    IA, USA
    FTP would be the easiest. There's open source libraries for FTP on virtually every language. LAN/network share would be ideal though.
     
    Crunching for Team TPU
  6. shuggans

    Joined:
    Dec 22, 2007
    Messages:
    175 (0.07/day)
    Thanks Received:
    7
    Location:
    Central Nebraska
    I need to use a file transfer solution in conjunction with the filesystemwatcher class on the client. The client app will need to wait until the file is done growing in size before sending(or can I send bytes as they are added to a file?)
     
  7. DanTheBanjoman Señor Moderator

    Joined:
    May 20, 2004
    Messages:
    10,553 (2.77/day)
    Thanks Received:
    1,383
  8. shuggans

    Joined:
    Dec 22, 2007
    Messages:
    175 (0.07/day)
    Thanks Received:
    7
    Location:
    Central Nebraska
    I need to use a file transfer solution in conjunction with the filesystemwatcher class on the client. The client app will need to wait until the file is done growing in size before sending(or can I send bytes as they are added to a file?)

    I found this code:

    Code:
    Imports System.Net.Sockets
    Imports System.Text
    Module Module1
        Sub Main()
            Dim serverSocket As New TcpListener(8888)
            Dim requestCount As Integer
            Dim clientSocket As TcpClient
            serverSocket.Start()
            msg("Server Started")
            clientSocket = serverSocket.AcceptTcpClient()
            msg("Accept connection from client")
            requestCount = 0
    
            While (True)
                Try
                    requestCount = requestCount + 1
                    Dim networkStream As NetworkStream = _
                            clientSocket.GetStream()
                    Dim bytesFrom(10024) As Byte
    networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
                    Dim dataFromClient As String = _
                            System.Text.Encoding.ASCII.GetString(bytesFrom)
                    dataFromClient = _
                dataFromClient.Substring(0, dataFromClient.IndexOf("$"))
                    msg("Data from client -  " + dataFromClient)
                    Dim serverResponse As String = _
                        "Server response " + Convert.ToString(requestCount)
                    Dim sendBytes As [Byte]() = _
                        Encoding.ASCII.GetBytes(serverResponse)
                    networkStream.Write(sendBytes, 0, sendBytes.Length)
                    networkStream.Flush()
                    msg(serverResponse)
                Catch ex As Exception
                    MsgBox(ex.ToString)
                End Try
            End While
    
    
            clientSocket.Close()
            serverSocket.Stop()
            msg("exit")
            Console.ReadLine()
        End Sub
    
        Sub msg(ByVal mesg As String)
            mesg.Trim()
            Console.WriteLine(" >> " + mesg)
        End Sub
    End Module
    But it looks like it's jsut used to send text data. what do i need to do to stream receive a file instead of text?
     
  9. DanTheBanjoman Señor Moderator

    Joined:
    May 20, 2004
    Messages:
    10,553 (2.77/day)
    Thanks Received:
    1,383
    I would recommend uploading via FTP. Writing just a client is a lot easier than writing both server and client. Besides, tcplistener is deprecated, it might create new headaches later on.
     
  10. shuggans

    Joined:
    Dec 22, 2007
    Messages:
    175 (0.07/day)
    Thanks Received:
    7
    Location:
    Central Nebraska
    I have a server app already I want this to integrate with, writing the tcplistener peice wouldn't be any more of a headache than I've gone through already :p. Is FTP as fast as writing a client/server transfer?
     
  11. DanTheBanjoman Señor Moderator

    Joined:
    May 20, 2004
    Messages:
    10,553 (2.77/day)
    Thanks Received:
    1,383
    Depending on how crappy the code you end up with is it might be faster. Expect full bandwidth usage from FTP. Perhaps you can just use ftp.exe in your application, at least as a place holder. Takes 5min to write that way.
     
  12. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,796 (6.26/day)
    Thanks Received:
    3,678
    Location:
    IA, USA
    That can be done separately. Just put in a Timer that checks the filesize periodically and once it hasn't changed for so long, then invoke FTP or File.Copy.

    It doesn't matter what solution you use, you really have to wait because it is good practice to start the file transfer with the file size. That way it will be abundantly obvious on the reciving end if the transfer is incomplete/failed.
     
    Crunching for Team TPU

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page