question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best approach - Zip file uploads from Client to Server (plus hash value check)

See original GitHub issue

Hello Everyone, and Happy New Year when it comes at your local time zone! 😃

I am asking for advice for best approach how I should use this WatsonTcp package. I need to upload ZIP files, one file per day from a Client application to a Server application. At both ends I would like to use WatsonTcp. The size of the Zip files varies between 50-150 MBytes.

I am thinking about the following:

  1. I create a FileStream from the zip file in the following way at the Client side (i only show part of the code):
using (FileStream fss = new FileStream(zipFilePath, FileMode.Open, FileAccess.Read))
                                    {
                                        using (SHA256 mySHA256 = SHA256.Create())
                                        {
                                            byte[] hashValue = mySHA256.ComputeHash(fss);
                                            Dictionary<object, object> metadata = new Dictionary<object, object>();
                                            metadata.Add(MetaData.FileName, Path.GetFileName(zipFilePath));
                                            metadata.Add(MetaData.FileSize, length);
                                            metadata.Add(MetaData.UploadStarted, DateTime.Now);
                                            metadata.Add(MetaData.CheckSum, hashValue);

                                            SyncResponse resp = Client.SendAndWait(ClientTimeout, fss.Length, fss, metadata);
                                            
                                            bool repliedHashOK = (bool)resp.Metadata[MetaData.CheckSumOK];
                                            if (repliedHashOK)  {}
                                            else {}
                                         }
                                    }

  1. At the server side, I register for the Callback “private static SyncResponse SyncRequestReceived(SyncRequest req)”. Inside this, I should recalculate the hash value of the FileStream, compare to the Value of the MetaData.CheckSum Key, then set the MetaData.CheckSumOK accordingly before sending the SyncResponse back to the Client.

Question:

I need to create the ZIP file at the Server side if the hash values match. For this, what data element can I use in the “private static SyncResponse SyncRequestReceived(SyncRequest req)” callback method? The “req.Data” is a byte array, I guess this array contains the same data what was sent by the Client.SendAndWait() method in the form of a FileStream? So I can calculate hash on this byte array, and I should be able to create the zip file from the byte array, yes?

Thanks very much for help, and any suggestions how I should do this file transfer better! Best Regards,

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jchristncommented, Jan 1, 2021

Hi @bukkideme definitely nothing wrong with running your code controlling both a server instance and a client instance like you would need to do on PC #2. The nice thing is that most of the underlying TCP work is already taken care of for you. You could very easily just implement a proxy of sorts in #2 that would listen for incoming streams and send them to #3. The hard part will be dealing with errors, i.e. #3 goes down prior to a response being fully sent back to #2 (that would be sent back to #1). Best of luck to you.

1reaction
jchristncommented, Dec 31, 2020

Exactly 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unrestricted File Upload | OWASP Foundation
Uploaded files can be abused to exploit other vulnerable sections of an application when a file on the same or a trusted server...
Read more >
How to Upload Large Files Using Plain JavaScript
Due to the uniqueness of the hash, once the server can find the file with the same hash, then just return the successful...
Read more >
File Upload Cheat Sheet
File upload is becoming a more and more essential part of any application, where the user is able to upload their photo, their...
Read more >
Verify file hash after FTP upload
This article describes how to check the file checksum after upload to FTP server using the Ultimate FTP. You can use CRC, MD5,...
Read more >
Best way of identifying and comparing files in a client- ...
Is there a way – a tricky secondary check maybe – to tell that the datasets with the matching checksums differ? Or the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found