Click here to Skip to main content
15,886,030 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is Server Code for Receiving Files

C#
int bytesSize = 0;


               byte[] downBuffer = new byte[2048];

               bytesSize = strRemote.Read(downBuffer, 0, 2048);

               string FileName = System.Text.Encoding.ASCII.GetString(downBuffer, 0, bytesSize);

               strLocal = new FileStream(@"F:\" + FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);


               downBuffer = new byte[2048];

               bytesSize = strRemote.Read(downBuffer, 0, 2048);

               long FileSize = Convert.ToInt64(System.Text.Encoding.ASCII.GetString(downBuffer, 0, bytesSize));


This is client code for getting files

strRemote = tcpClient.GetStream();
                byte[] byteSend = new byte[tcpClient.ReceiveBufferSize];
          
                fstFile = new FileStream(openFile.FileName, FileMode.Open, FileAccess.Read);
           
                BinaryReader binFile = new BinaryReader(fstFile);

          
                FileInfo fInfo = new FileInfo(openFile.FileName);

            
                string FileName = fInfo.Name;
             
                byte[] ByteFileName = new byte[2048];
                ByteFileName = System.Text.Encoding.ASCII.GetBytes(FileName.ToCharArray());
          
                strRemote.Write(ByteFileName, 0, ByteFileName.Length);

              
                long FileSize = fInfo.Length;
          
                byte[] ByteFileSize = new byte[2048];
                ByteFileSize = System.Text.Encoding.ASCII.GetBytes(FileSize.ToString().ToCharArray());
              
                strRemote.Write(ByteFileSize, 0, ByteFileSize.Length);

                txtLog.Text += "Sending the file " + FileName + " (" + FileSize + " bytes)\r\n";

                
                int bytesSize = 0;
            
                byte[] downBuffer = new byte[2048];

              
                while ((bytesSize = fstFile.Read(downBuffer, 0, downBuffer.Length)) > 0)
                {
                
                    strRemote.Write(downBuffer, 0, bytesSize);
                }
Posted
Comments
Aditya Chauhan 26-May-15 8:10am    
Please Explain What you wannna do ?
Srikanth59 26-May-15 8:43am    
This Application consists of Client and Server, which transfer files from client to server,but am unable receive files on the server.The client is sending files but server unable to receive files
Aditya Chauhan 26-May-15 9:29am    
Ok I have done this type of work in the last week
this is very simple ,
Your server is linux ?
Srikanth59 26-May-15 9:34am    
no my server is Windows
Sergey Alexandrovich Kryukov 26-May-15 9:33am    
Sorry, this is not a question, just some code dump. You need to explain the problem properly.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900