I have wrote a C# console application to copy lots of small XML files (about 80000 files, round about 300KB each, total size of about 3GB gets transferred) from a share directory on an AS400 Machine to a share directory on a windows Machine.
The two machine are on the same LAN, but it is taking many hours to do the copying. I need to loop through the files, as I need to update a table in the DB, I know this could maybe the bottle neck, but excluding the SQL update; Is there a faster way to transfer these files?
public void CopyFiles()
{
DirectoryInfo IFS = new DirectoryInfo(@"\\AS400Machine\ShareFolder\");
string NewPath = @"\\WindowsMachine\ShareFolder\";
Directory.CreateDirectory(NewPath);
foreach (FileInfo xmlFile in IFS.GetFiles())
{
var newFullPath = string.Format(@"{0}\{1}", NewPath, xmlFile.Name);
// SQL Update
// Copy File
xmlFile.CopyTo(newFullPath, true);
}
}
If your program runs on Machine C and it transfers files from Machine A to Machine B, there's not much you can do here except doing the copying in multiple threads or processes.
If you could run your program on both machines, you could do some nifty tricks like zipping the files up so that you'd be transferring a single (or several) large files instead of thousand of small ones.