Sending Files over a Windows Network

I am trying to send files from one computer to the other over a windows network. I have absolute path names of the two locations.

Can you just use "File.renameTo(File);" to pull this off?

Is there a fast way to move files over a windows network?

Thanks so much for your help

[302 byte] By [punkrawk0568a] at [2007-11-27 10:43:19]
# 1

> I am trying to send files from one computer to the

> other over a windows network. I have absolute path

> names of the two locations.

>

> Can you just use "File.renameTo(File);" to pull this off?

Why not try it?

prometheuzza at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 2

Haha, I guess I should have worded my question better. What I meant to say is I am trying it and it doesn't seem to work and I was wondering if this makes sense or if there is a different way to do it that I am overlooking?

punkrawk0568a at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 3

> Haha, I guess I should have worded my question

> better. What I meant to say is I am trying it and it

> doesn't seem to work and I was wondering if this

> makes sense or if there is a different way to do it

> that I am overlooking?

If you have the sufficient rights on the source and destination locations, and if the file you want to move is not opened by some other process, you should be able to do it, yes. Note that the method itself returns a boolean whether the moving of the file succeeded.

prometheuzza at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 4

Thanks, I am wasn't sure if my program wasn't succeeding because of the move attempts or if it was something else. I will post if I figure anything significant out. Thanks for your help.

punkrawk0568a at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 5

> Thanks, I am wasn't sure if my program wasn't

> succeeding because of the move attempts or if it was

> something else. I will post if I figure anything

> significant out. Thanks for your help.

It's usually fails because it's still opened by another process (i.e. an unclosed stream or something similar)

prometheuzza at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 6

Let's say I am sending a file from "C:/Email/file.txt" to "//CoolComputer/Email/". When I use the renameTo function it creates a local directory in the relative path of my .class file called "185CoolComputer/Email/file.txt" but it doesn't send it over the network.

The renameTo function is returning TRUE.

Any idea what is going on there?

Basically my code says,

File newFile = new File("C:/Email/file.txt");

File newFolder = new File("//CoolComputer/Email");

newFile.renameTo(new File(newFolder, newFile.getName());

punkrawk0568a at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 7

> Let's say I am sending a file from

> "C:/Email/file.txt" to "//CoolComputer/Email/". When

> I use the renameTo function it creates a local

> directory in the relative path of my .class file

> called "185CoolComputer/Email/file.txt" but it

> doesn't send it over the network.

> The renameTo function is returning TRUE.

> Any idea what is going on there?

And what is the problem?

prometheuzza at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 8

It isn't sending it over the network, it is just creating a local directory with the network name that I am trying to send to.

punkrawk0568a at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 9

> It isn't sending it over the network, it is just

> creating a local directory with the network name that

> I am trying to send to.

That's too bad. The API docs mention that that this operation is platform-dependent, and sending it from one machine to another is asking for even more trouble I suspect.

You could try to just create a new file (using Java) in the destination folder to see if that succeeds.

Good luck with it.

prometheuzza at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 10

rename is not a file sending or copying operation. It is an operation on directories. It doesn't even work between e.g. C: and D: on the local machine, let alone across a network.

ejpa at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 11

> rename is not a file sending or copying operation. It

> is an operation on directories. It doesn't even work

> between e.g. C: and D: on the local machine, let

> alone across a network.

Err, I can move files between local directories: I just tried it. I can also move it from my local machine to a file server I have hooked up on my router.

prometheuzza at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 12

With File.renameTo()? between directories on different local drives? or different nodes in a network?

ejpa at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 13

> With File.renameTo()?

Yes.

> between directories on different local drives?

Yes.

> or different nodes in a network?

I'm not sure what you mean by that, which is most probably my lack of knowledge about computer networking.

Here's the test I performed:

File a = new File("C:/Temp/test.txt");

// 'E:' is (physicaly) a different hard drive than 'C:'

File b = new File("E:/Temp/test.txt");

System.out.println(a.renameTo(b));

// 'Athene' is a home-SAN-drive/server connected to my router

File c = new File("//Athene/SHARE/Temp/test.txt");

System.out.println(b.renameTo(c));

Both print true and in both cases I have checked to see if the files really were moved, which was the case.

prometheuzza at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 14

So why doesn't it work for the OP?

ejpa at 2007-7-28 19:59:34 > top of Java-index,Core,Core APIs...
# 15

> So why doesn't it work for the OP?

Take your pick ; )

- perhaps he is using a user/password protected network location which Windows is authenticating for him. Java will not be able to write there. At least, I am not able to do that.

- another possibility is that a (Windows) process is locking the source file preventing it from removing.

- there can also be problems with moving from various file systems like NTFS, FAT/32, EXT2, ... you name it (don't know details I'm afraid). In my case, everything is written from NTFS to NTFS.

- but the most likely thing (at least what I see happening here at the forums) is that the OP is trying to move a file which s/he has just been writing to and forgot to close the underlying stream.

prometheuzza at 2007-7-28 19:59:39 > top of Java-index,Core,Core APIs...
# 16

I have never been able to move files between volumes (networked or otherwise) so these days I don't even try. As far as I can remember, the last time I did try it was with 1.2.2 so maybe there has been a significant update to File.renameTo() since then.

What version of Java are you using prom. What version of Java is the OP using.

Message was edited by:

sabre150

sabre150a at 2007-7-28 19:59:39 > top of Java-index,Core,Core APIs...
# 17

>...

> What version of Java are you using prom.

I am using Sun's JDK 1.6.

prometheuzza at 2007-7-28 19:59:39 > top of Java-index,Core,Core APIs...
# 18

It's not an upgrade to File.renameTo(), it's the capabilities of the underying Win32 _wrename(). According to the current documentation it can indeed do all those things as Promethuezz says so I am a dolt. Things have changed a lot since I was a lad. I learnt all those APIs from the old DOS Famliy API and DosMove() and DosCopy() were distinct things. But that's about 15 years go, DOS 5.

ejpa at 2007-7-28 19:59:39 > top of Java-index,Core,Core APIs...