• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.
  • The forums have been upgraded with support for dark mode. By default it will follow the setting on your system/browser. You may override it by scrolling to the end of the page and clicking the gears icon.

Network File Transfer vb.net

Joined
Dec 22, 2007
Messages
184 (0.03/day)
Location
Central Nebraska
System Name CORSAIR
Processor AMD Phenom 1090T x6 @3.2
Motherboard Gigabyte Ga-78LMT-S2P
Cooling High efficiency dust cooling
Memory 8GB GSkill DDR3 1333
Video Card(s) Sapphire Radeon HD3870 512MB GDDR4 PCI-e toxic
Storage Seagate SV35.3 ST3250310SV 250GB SATAII(Windows 7 Pro x64), 320GB Samsung SATAII(Storage and SuSE)
Display(s) Dell 20" LCD, Dell 17" LCD
Power Supply Antec Cool Blue 650W Modular
Software Windows 7 Professional SP1, Visual Studio 2010 Ultimate
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.
 
Network shares are out of the question for my purposes
 
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.
 
FTP would be the easiest. There's open source libraries for FTP on virtually every language. LAN/network share would be ideal though.
 
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 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?
 
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.
 
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?
 
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.
 
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?)
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.
 
Back
Top