1

I created a service that moves certain file types in a directory to another one, this works fine locally and pretty fast over my network. On a different network though it works incredibly slow (a 500mb file takes 6 1/2 minutes) but the same file copied and pasted into the folder via explorer is complete in about 30/40 seconds.

Snippet where file move happens.

currentlyProcessing.Add(currentFile.FullName);
try
{
    eventMsg("Attempting to move file","DEBUG");

    File.Move(oldFilePath, newFilePath);
    eventMsg("File Moved successfully","DEBUG");


}
catch (Exception ex)
{
    eventMsg("Cannot Move File another resource is using it", "DEBUG");
    eventMsg("Move File Exception : " + ex, "DEBUG");

}
finally
{ 
    if(File.Exists(currentFile.FullName + ".RLK"))
    {
        try
        {
            File.Delete(currentFile.FullName + ".RLK");
        }
        catch (IOException e)
        {
            eventMsg("File Exception : " + e, "DEBUG");
        }

    }
    currentlyProcessing.Remove(oldFilePath);
}

I fear the code is fine (as it works as expected on other network) so the problem is probably the network, in some shape or form. Has anyone got any common tips to check, the service runs as local system(or Network service) and there doesn't seem to be access problem. What other factors would affect this (other than network/hardware) .

What I would like is it to have a similar transfer speed to that I've witnessed in Explorer. Any pointers greatly appreciated .

Danpe
  • 18,668
  • 21
  • 96
  • 131
user685590
  • 2,464
  • 5
  • 30
  • 42

2 Answers2

0

First of all Ping each other to check latency so you can see if it's the problem is globally in the network or is it something with your software.

cmd ping 192.168.1.12 -n 10

If it's a problem on the network follow this:

  1. Restart your HUB / Router
  2. Is one of the PCs use WiFi with low signal?
  3. Is there any Anti Virus that is turned on and monitoring Network Activity ?

If none of the above solves your problem then try using WireShark to be able to further investigate the issue.

Danpe
  • 18,668
  • 21
  • 96
  • 131
0

For files with such huge size, I would suggest zipping them up if possible, especially since network latency is always a big factor involved in upload/download of files over the internet. You can zip your files with System.IO.Packaging. Have a look here Using System.IO.Packaging to generate a ZIP file , specifically:

using (Package zip = System.IO.Packaging.Package.Open(zipFilename, FileMode.OpenOrCreate))
        {
            string destFilename = ".\\" + Path.GetFileName(fileToAdd);
            Uri uri = PackUriHelper.CreatePartUri(new Uri(destFilename, UriKind.Relative));
            if (zip.PartExists(uri))
            {
                zip.DeletePart(uri);
            }
            PackagePart part = zip.CreatePart(uri, "",CompressionOption.Normal);
            using (FileStream fileStream = new FileStream(fileToAdd, FileMode.Open, FileAccess.Read))
            {
                using (Stream dest = part.GetStream())
                {
                    CopyStream(fileStream, dest);
                }
            }
        }

Also, you can should FTP as some other user mentioned if possible. Look at the Renci SSHNet library on CodePlex.

Community
  • 1
  • 1
tranceporter
  • 2,241
  • 1
  • 21
  • 23