Transfer file to many cilent with IP address using C#


  • Hi is it possible to use a main computer (C#) and transfer files to many cilents (many computers) with available IP addresses using C# ? is there any source to find this? Thanks
    Thursday, September 19, 2013 9:16 AM


All replies

  • Yes, of course it is possible. In the main PC you would write a loop sending the file to each of the clients. Depending on your needs, this could be sequential or you could even do it asynchronously and send the files simultaneously to several clients.

    If the network firewalls allow it, you could simply use the Windows networking to copy the files. Create a share at each client, and in the main pc just execute a System.IO.File.Copy(source, destination) and use a UNC with the share name to indicate each of the clients. In other words, destination=@"\\ipaddress\sharename\filename".

    If the individual PCs do not allow sharing files over the network, then the situation is more complex. You could write a small program to run at each PC to accept files over a given TCP port (which you would need to open in the firewall), then comunicate with that program from your main program (for how to program this type of communication, search for WCF - Windows Communication Foundation). Or alternatively, if you are allowed, enable on every PC a piece of existing sotware that can do this, for instance, enable Internet Information Server and then upload the files using the WebClient class.

    As you see, there are many alternatives, which would depend on your specific situation. Some more information would be needed in order to provide a more specific answer.

    Thursday, September 19, 2013 9:27 AM
  • I need to create a windows form application using C#. May i know which is the easier way to do to transfer the files to the cilent? i've the ip address on the LAN now but i need to think of something to use the IP address to make it useful. I'm still a newbie in programming and learning.. is there any advice you could give? 
    Thursday, September 19, 2013 9:35 AM
  • Well, three questions firsts:

    1. What is your scenario (context)?
    2. Do you need to push the files or may pulling an option?
    3. Must it transmitted by stream or is block an option?
    Thursday, September 19, 2013 9:45 AM
  • okay.. first

    1) My C# form is able to ping the subnet and the available IP address will reply to me this includes router, switch, printer and PC. Therefore i have the IP address now, my idea is to transfer any file e.g. text file to the client in the lab. Another idea is i think of is to send a message to all the user so that the message will appear on their computer if they are connected (still researching on it).

    2) The idea is to send the files to client so it should be push the fiiles.

    3) It could be transmitted by stream. I'm not too sure whether the lab the firewall is block.

    Thursday, September 19, 2013 9:54 AM
  • Does the server support FTP to transfer files?   You can check by putting into your webbrowsewer the following



    Thursday, September 19, 2013 10:53 AM
  • I see, to cryptic questions ;)

    What I had in mind: When the clients may pull the files - instead of the server pushing them - and block transmission - instead of streaming these files - is possible: Then why not simply exchanging the files over a SMB/CIFS share?

    Thursday, September 19, 2013 11:00 AM
  • erm i got an error no address found in my browser.. 
    Thursday, September 19, 2013 11:25 AM
  • Hi what SMB/CIFS ? im still a newbie dont know anything about this.. my intention is to send files to many computer using C#.. 
    Thursday, September 19, 2013 11:27 AM
  • How hard could it be? SMB/CIFS.

    But you may explain what are you trying to achieve? A little bit more context would be nice. Why would you do that?

    E.g. Sending Files using TCP.

    Thursday, September 19, 2013 11:40 AM
  • Okay.. to put in simple, i'm creating a program for my project using C# windows form. So as to simplify my lecturers and the student in the lab, the lecturer may sometimes transfer files to his students so that all the students could access the files using my program. Basically if the lecturer need to copy the files to the students, he just need to use my program (C#) to choose the file he wants then he will upload so that his students all could access the same files he give..
    Thursday, September 19, 2013 11:43 AM
  • File, what kind of files?
    Thursday, September 19, 2013 11:49 AM
  • It could be text file, pdf file, program file, music etc..
    Thursday, September 19, 2013 11:50 AM
  • Are the students PC there own lap tops or school computer?  The better method woud be to make on the teacher PC a shared folder that the student can pull the files.  This way you don't have to set up the permissions on all the students PCs.  The students wil be able to easily access the files.  Your application could move the files on the teacher PC to the shared folder so the student only have access to the needed files.


    Thursday, September 19, 2013 11:54 AM
  • the students will be using the school computer in the lab. if possible, the student might bring their laptop to tap into the school wifi. ah! this sounds a better idea. is there any way i could start from so that the lecturer could choose what files to give and put into the share folder? and how does the student access the shared folder on the school computers or their laptops?
    Thursday, September 19, 2013 12:01 PM
  • Either map the drive, or type \\servername\ in a windows explorer or in an  IE.


    Thursday, September 19, 2013 12:07 PM
  • The teacher would have to setup there own private folders for each day lesson and then the form could choose which folders to move to the shared folder.


    Thursday, September 19, 2013 12:09 PM
  • Why not simply using a web-based CMS?
    Thursday, September 19, 2013 12:18 PM
  • so meaning everytime when he want transfer file, he need to set up the folder so the student can access? it would be a little hassle for him though.. can he upload the files to the FTP server and the students could access the file on their own?
    Thursday, September 19, 2013 12:53 PM
  • Erm I'm trying to integrate with my C# program so make it simple..
    Thursday, September 19, 2013 12:53 PM
  • I doesn't have to be a FTP server.  I could be his own PC.  It could either be FTP or just a COPy over the network.  All he would need to do is to make a folder shared by right clicking on the folder in window explorer and selecting shared.  Each teacher is different.  Some may decide to put all the files for the semester on the shared drive at the beginning of the semester.   Others may want to do it more often especially if they don't have all the files prepared ahead of time.


    Thursday, September 19, 2013 12:57 PM
  • oh okay.. so how should I go about it to start to program using C# ? is there any sample code ?
    Thursday, September 19, 2013 1:08 PM
  • Because i don't want to make it that it seem to be very easy, as this is my FYP project..
    Thursday, September 19, 2013 1:11 PM
  • You jsut need to add the namespace "using System.IO;" and use the methods in Files Class and Directory Class.


    Thursday, September 19, 2013 1:25 PM
  • huh ok.. is there any sample code to refer? i'm really not good in my programming..
    Thursday, September 19, 2013 1:27 PM
  • Hi,

    I think what you need is a chat program which is able to transfer files. And it'll show up from background whenever it receives a file or a message.

    Microsoft has provided Sockets and TcpClient or TcpListener which would help you with that.

    About sending messages, please see:

    About sending files, please see:

    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, September 20, 2013 9:29 AM
  • thanks caillen for the resource! greatly appreciated. however the thing I want to implement is the server (lecturer) can make a announcement and all the cilent will receive e.g. "There will be will a lab test next week" and all the client (students) will know and the client will not reply back. so is something like a one way message from the server to client. a broadcast message I should say..
    • Edited by Myusic Friday, September 20, 2013 10:00 AM
    Friday, September 20, 2013 10:00 AM
  • Then maybe the code of this poster in this thread may give you some help:

    I think you need to spend some time on Network Programming in C#.

    The more you research and code, the more you'll learn, that's the point. To get the ready-made code from others is not a good idea.

    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Sunday, September 22, 2013 11:33 AM
  • thanks caillen how do you find all these resources? I searched on google for many days still couldn't find the sample code I wanted.. and yes, I will read the network programming in C# :)
    Sunday, September 22, 2013 1:31 PM