473,326 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Transferring files to another machine on a local network

I need to move a jpeg file to another machine on a local network (for
which I have full permissions). The following works:

*****************
string inputPath = @"C:/test.jpg";
string outputPath = @"\\OTHERCOMPUTER\test.jpg";

FileStream fin = new FileInfo(inputPath, FileMode.Open);
FileStream fout = File.Create(outputPath);

BinaryReader br = new BinaryReader(fin);
BinaryWriter bw = new BinaryWriter(fout);

long length = fin.Length; // cache this value
int size = 1048576; // 1 megabyte
byte[] bytes = new byte[size];
long position = 0;

while (position < length)
{
bytes = br.ReadBytes(size);
bw.Write(bytes);
position += size;
}

br.Close();
bw.Close();

fin.Close();
fout.Close();

new FileInfo(inputPath).Delete(); // get rid of old file
*****************

It works, but it is INCREDIBLY slow. It takes something like 200
seconds to transfer a 1MB photo (ANTS profiler says
Win32Native.WriteFile(SafeFileHandle, byte*, int, out int, IntPtr) is
the holdup). When I copy-paste these files in the Windows Explorer,
they transfer in under a second, so I thought perhaps the kernel was
being smart about the SMB networking, so I tried this:

*****************
[DllImport("kernel32.dll")]
static extern bool MoveFile(string lpExistingFileName, string
lpNewFileName);

private void Move(string inputPath, string outputPath)
{
MoveFile(inputPath, outputPath);
}
*****************

But this was just as slow. Apparently, Windows Explorer is smart about
browsing remote folders and will use some SMB-or-other API function
when copy/pasting files. Does anyone know what that API call is, and
how I ought to wrap it?

Mar 15 '07 #1
7 10212
But this was just as slow. Apparently, Windows Explorer is smart about
browsing remote folders and will use some SMB-or-other API function
when copy/pasting files. Does anyone know what that API call is, and
how I ought to wrap it?
Are you sure Explorer has finished copying the file? If you disconnected
the network, you might find that the copy didn't finish so fast after all.
Mar 16 '07 #2
On Mar 15, 5:43 pm, "Ben Voigt" <r...@nospam.nospamwrote:
But this was just as slow. Apparently, Windows Explorer is smart about
browsing remote folders and will use some SMB-or-other API function
when copy/pasting files. Does anyone know what that API call is, and
how I ought to wrap it?

Are you sure Explorer has finished copying the file? If you disconnected
the network, you might find that the copy didn't finish so fast after all.
Yes, it really does transfer in a second or two.

Mar 16 '07 #3
VJ
Oh explorer takes progress out before finishing copying.. that is scary
Ok I know you did not mean that.. but I got it like that, and jumped a
little...

Although I have seen explorer do it for USB locations.. and corrupted a
drive of mine...

VJ

"Ben Voigt" <rb*@nospam.nospamwrote in message
news:e9**************@TK2MSFTNGP03.phx.gbl...
>But this was just as slow. Apparently, Windows Explorer is smart about
browsing remote folders and will use some SMB-or-other API function
when copy/pasting files. Does anyone know what that API call is, and
how I ought to wrap it?

Are you sure Explorer has finished copying the file? If you disconnected
the network, you might find that the copy didn't finish so fast after all.

Mar 16 '07 #4
"Lunchtimemama" <lu***********@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
>I need to move a jpeg file to another machine on a local network (for
which I have full permissions). The following works:

*****************
string inputPath = @"C:/test.jpg";
string outputPath = @"\\OTHERCOMPUTER\test.jpg";

FileStream fin = new FileInfo(inputPath, FileMode.Open);
FileStream fout = File.Create(outputPath);

BinaryReader br = new BinaryReader(fin);
BinaryWriter bw = new BinaryWriter(fout);

long length = fin.Length; // cache this value
int size = 1048576; // 1 megabyte
byte[] bytes = new byte[size];
long position = 0;

while (position < length)
{
bytes = br.ReadBytes(size);
bw.Write(bytes);
position += size;
}

br.Close();
bw.Close();

fin.Close();
fout.Close();

new FileInfo(inputPath).Delete(); // get rid of old file
*****************

It works, but it is INCREDIBLY slow. It takes something like 200
seconds to transfer a 1MB photo (ANTS profiler says
Win32Native.WriteFile(SafeFileHandle, byte*, int, out int, IntPtr) is
the holdup). When I copy-paste these files in the Windows Explorer,
they transfer in under a second, so I thought perhaps the kernel was
being smart about the SMB networking, so I tried this:

*****************
[DllImport("kernel32.dll")]
static extern bool MoveFile(string lpExistingFileName, string
lpNewFileName);

private void Move(string inputPath, string outputPath)
{
MoveFile(inputPath, outputPath);
}
*****************

But this was just as slow. Apparently, Windows Explorer is smart about
browsing remote folders and will use some SMB-or-other API function
when copy/pasting files. Does anyone know what that API call is, and
how I ought to wrap it?


There is no tricky API used by Explorer. Didn't look at your code, but there must be
something wrong with it.
Using following takes less than 10 seconds to copy a 30MB file to a network share over a
100Mbit ethernet link

....
string outPath = @"\\othercomputer\test.jpg";
string inPath = @"c:\test.jpg";
{
using (FileStream fso = File.OpenWrite(outPath))
using (FileStream fsi = File.OpenRead(inPath))
{
byte[] b = new byte[4096];
int offset = 0;
int bytesRead = 0;
while ((bytesRead = fsi.Read(b, offset, b.Length)) 0)
{
fso.Write(b, offset, bytesRead);
}
}
}
Willy.

Mar 16 '07 #5
On Mar 16, 5:13 am, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
"Lunchtimemama" <lunchtimem...@gmail.comwrote in message

news:11**********************@l77g2000hsb.googlegr oups.com...
I need to move a jpeg file to another machine on a local network (for
which I have full permissions). The following works:
*****************
string inputPath = @"C:/test.jpg";
string outputPath = @"\\OTHERCOMPUTER\test.jpg";
FileStream fin = new FileInfo(inputPath, FileMode.Open);
FileStream fout = File.Create(outputPath);
BinaryReader br = new BinaryReader(fin);
BinaryWriter bw = new BinaryWriter(fout);
long length = fin.Length; // cache this value
int size = 1048576; // 1 megabyte
byte[] bytes = new byte[size];
long position = 0;
while (position < length)
{
bytes = br.ReadBytes(size);
bw.Write(bytes);
position += size;
}
br.Close();
bw.Close();
fin.Close();
fout.Close();
new FileInfo(inputPath).Delete(); // get rid of old file
*****************
It works, but it is INCREDIBLY slow. It takes something like 200
seconds to transfer a 1MB photo (ANTS profiler says
Win32Native.WriteFile(SafeFileHandle, byte*, int, out int, IntPtr) is
the holdup). When I copy-paste these files in the Windows Explorer,
they transfer in under a second, so I thought perhaps the kernel was
being smart about the SMB networking, so I tried this:
*****************
[DllImport("kernel32.dll")]
static extern bool MoveFile(string lpExistingFileName, string
lpNewFileName);
private void Move(string inputPath, string outputPath)
{
MoveFile(inputPath, outputPath);
}
*****************
But this was just as slow. Apparently, Windows Explorer is smart about
browsing remote folders and will use some SMB-or-other API function
when copy/pasting files. Does anyone know what that API call is, and
how I ought to wrap it?

There is no tricky API used by Explorer. Didn't look at your code, but there must be
something wrong with it.
Using following takes less than 10 seconds to copy a 30MB file to a network share over a
100Mbit ethernet link

...
string outPath = @"\\othercomputer\test.jpg";
string inPath = @"c:\test.jpg";
{
using (FileStream fso = File.OpenWrite(outPath))
using (FileStream fsi = File.OpenRead(inPath))
{
byte[] b = new byte[4096];
int offset = 0;
int bytesRead = 0;
while ((bytesRead = fsi.Read(b, offset, b.Length)) 0)
{
fso.Write(b, offset, bytesRead);
}
}
}

Willy.
Using that exact code, it still takes forever. Perhaps it's something
with my network. Is there any reason Win32Native.WriteFile might get
hung up?

Mar 16 '07 #6
JS
I have an application where I'm doing a similar file copy (never timed
it but it did not seem slow). I had a problem which was a bit
different. The other computer required a different username/password,
so the copy would not work unless I 'seeded' Windows by first opening
an explorer window to the other computer, then entering the username
and password. After this, Windows knew I was trusted I guess. Still,
I'd like to be able to somehow do the file copy in code without having
this prerequisite. Does anyone know how to do a file copy to a share
on a different computer where the other computer has a different
username/password?

Thanks.

Mar 16 '07 #7
On Mar 15, 5:21 pm, "Lunchtimemama" <lunchtimem...@gmail.comwrote:
I need to move a jpeg file to another machine on a local network (for
which I have full permissions). The following works:

*****************
string inputPath = @"C:/test.jpg";
string outputPath = @"\\OTHERCOMPUTER\test.jpg";

FileStream fin = new FileInfo(inputPath, FileMode.Open);
FileStream fout = File.Create(outputPath);

BinaryReader br = new BinaryReader(fin);
BinaryWriter bw = new BinaryWriter(fout);

long length = fin.Length; // cache this value
int size = 1048576; // 1 megabyte
byte[] bytes = new byte[size];
long position = 0;

while (position < length)
{
bytes = br.ReadBytes(size);
bw.Write(bytes);
position += size;

}

br.Close();
bw.Close();

fin.Close();
fout.Close();

new FileInfo(inputPath).Delete(); // get rid of old file
*****************

It works, but it is INCREDIBLY slow. It takes something like 200
seconds to transfer a 1MB photo (ANTS profiler says
Win32Native.WriteFile(SafeFileHandle, byte*, int, out int, IntPtr) is
the holdup). When I copy-paste these files in the Windows Explorer,
they transfer in under a second, so I thought perhaps the kernel was
being smart about the SMB networking, so I tried this:

*****************
[DllImport("kernel32.dll")]
static extern bool MoveFile(string lpExistingFileName, string
lpNewFileName);

private void Move(string inputPath, string outputPath)
{
MoveFile(inputPath, outputPath);}

*****************

But this was just as slow. Apparently, Windows Explorer is smart about
browsing remote folders and will use some SMB-or-other API function
when copy/pasting files. Does anyone know what that API call is, and
how I ought to wrap it?
I'm on a wireless network, if that makes a difference.

Mar 18 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John | last post by:
Hello, I need to know which programs are opn on another machine in my network, these programs are opened from a shared drive on the server. How can I do this ? I've already dowloaded a sample...
6
by: Job Lot | last post by:
Using VB.NET how can I find all available SQL Server on a local network and list all the databases in each server. Thanks
29
by: Tola | last post by:
In my case of study, my teacher gave me a project, after I analysed the problem I found that I had to used open the file on the other machine? Please help? Thank you in advance. Tola CHROUK
8
by: GeekBoy | last post by:
I understand the benefit of pushing the StateServer process onto another computer to "balance" the load and take some cpu and memory usage off the web server, but how much could it possibly help?...
27
by: Javier Martinez | last post by:
Hi I have asp application in a machine with a virtual directory referring a shared directory in another machine When I try to load any aspx page of my portal I get the following error: ...
1
by: gudmewarshivnath | last post by:
hi I need to access the files & folders from another machine which is in the network then how can i impliment it in vb 6 Is there any API Plz someone help me Shivnath
0
by: sang | last post by:
Hi i want to connect the another machine in mysql which is located in the network. by using this i want to access the another machine database with my system. The accessed machine is...
0
by: umeshpotdar | last post by:
hi friends i have created asp.net project i want to execute it on another machine which is connected to my machine.(i.e in LAN) so how can i execute this ? can you tell me?
22
by: hamarsheh | last post by:
please i need you'r help .. we are designing a web site and we need a critical code in php for security , we have to read users permissions on files in the local network ,to give them the real...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.