public void upLoadFile(FileTransferMessage msg)
 {
     int totalBytes = 0;
     hrt.Start();
     filename = msg.filename;
     string rfilename = Path.Combine(savePath, filename);
     if (!Directory.Exists(savePath))
         Directory.CreateDirectory(savePath);
     using (var outputStream = new FileStream(rfilename, FileMode.Create))
     {
         while (true)
         {
             int bytesRead = msg.transferStream.Read(block, 0, BlockSize);
             totalBytes += bytesRead;
             if (bytesRead > 0)
                 outputStream.Write(block, 0, bytesRead);
             else
                 break;
         }
     }
     hrt.Stop();
     Console.Write(
       "\n  Received file \"{0}\" of {1} bytes in {2} microsec.",
       filename, totalBytes, hrt.ElapsedMicroseconds
     );
 }
Beispiel #2
0
 //function to upload files
 public void uploadFile(string filename, string path)
 {
     string fqname = Path.Combine(path, filename);
     try
     {
         using (var inputStream = new FileStream(fqname, FileMode.Open))
         {
             FileTransferMessage msg = new FileTransferMessage();
             msg.filename = filename;
             msg.transferStream = inputStream;
             channel.upLoadFile(msg);
         }
         Console.Write("\n  Uploaded file to RepoStorage \"{0}\"", filename);
     }
     catch
     {
         Console.Write("\n  can't find \"{0}\"", fqname);
     }
 }
Beispiel #3
0
 //function to upload file to remote location
 public void upLoadFile(FileTransferMessage msg)
 {
     int totalBytes = 0;
     filename = msg.filename;
     string rfilename = Path.Combine(savePath, filename);
     if (!Directory.Exists(savePath))
         Directory.CreateDirectory(savePath);
     using (var outputStream = new FileStream(rfilename, FileMode.Create))
     {
         while (true)
         {
             int bytesRead = msg.transferStream.Read(block, 0, BlockSize);
             totalBytes += bytesRead;
             if (bytesRead > 0)
                 outputStream.Write(block, 0, bytesRead);
             else
                 break;
         }
     }
 }
      public  void uploadFile(string filename)
        {
            string fqname = Path.Combine(ToSendPath, filename);
            try
            {
                hrt.Start();
                using (var inputStream = new FileStream(fqname, FileMode.Open))
                {
                    FileTransferMessage msg = new FileTransferMessage();
                    msg.filename = filename;
                    msg.transferStream = inputStream;
                    channel.upLoadFile(msg);
                }
                hrt.Stop();
                Console.WriteLine("\n**********************************************************************");
                Console.WriteLine("\nDemonstrating requirement 2 :");

                Console.Write("\n  Uploaded file \"{0}\" in {1} microsec.", filename, hrt.ElapsedMicroseconds);
            }
            catch(Exception message)
            {
                Console.Write("\n  can't find \"{0}\"", message);
            }
        }