folderitem.CopyFileTo Zero byte file

Hey all!
Have a weird issue and need some help. I have a mac app that is writing files from a ‘Spool’ directory to a folder that may be on network drive, possibly on a PC disk.
My application creates the file locally, no problem there. It then tries to copy the file to the remote directory and compares the file size of the local to result of the CopyfileTo method in the network directory. In some cases I get files that are Zero byte.

I’m trying to figure out why? If permission are restricting permission to write then why would I even get a zero byte file? Any insight into the low level process that the folderItem.CopyfileTo employs?
Any best practices I can employ to improve results when writing to network drives.

Rsync is best for network copy files
rsync

Are you copying the file before it has finished being created? Maybe check f.isWriteable or f.Length > 0 first?

We have plugin classes for file copy which also have progress and preserve extended file attributes.

Mac: http://www.monkeybreadsoftware.net/class-macfileoperationmbs.shtml
Windows: http://www.monkeybreadsoftware.net/class-windowsfilecopymbs.shtml

Greetings
Christian

Once the file has been copied, the remote copy shows as 0 bytes right? Have you opened it to double check the contents?

Yeah the file is created in a separate process and saved in a temporary spool folder. The size of this file is checked before the copy process. The problem only ever occurs when the file is tried to copy to a network location. The resulting zero byte file simply has a name and no content in the body. The original file still has the same size.
Obviously this points to some sort of “environmental” variable, but what perplexes me is how a file can be created with no content. Since the app just created the file in the local folder it has the ability to read/write. Not sure what the copyTo method is doing that would allow this to happen.

[quote=255051:@Julian Mussi]Yeah the file is created in a separate process and saved in a temporary spool folder. The size of this file is checked before the copy process. The problem only ever occurs when the file is tried to copy to a network location. The resulting zero byte file simply has a name and no content in the body. The original file still has the same size.
Obviously this points to some sort of “environmental” variable, but what perplexes me is how a file can be created with no content. Since the app just created the file in the local folder it has the ability to read/write. Not sure what the copyTo method is doing that would allow this to happen.[/quote]

This is probably worth a bug report.

Try rsync manually in the terminal, though. If it works, all you need to do is to shell to it.

I’ll look into rsync. Might be a good work around for this particular case.
Wondering if there’s any other best practices or approach I can take to ensure that a file copy is either exact or not created at all (boolean result).

Check https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/rsync.1.html

There are numerous options.

For rsync there is 2 options

--existing              skip creating new files on receiver

--existing, --ignore-non-existing This tells rsync to skip creating files (including directories) that do not exist yet on the destination. If this option is combined with the --ignore-existing option, no files will be updated (which can be useful if all you want to do is to delete extraneous files).

For more information check the link from Michel Bujardet

[quote=255304:@Julian Mussi]I’ll look into rsync. Might be a good work around for this particular case.
Wondering if there’s any other best practices or approach I can take to ensure that a file copy is either exact or not created at all (boolean result).[/quote]
If you use the shell always u get back an integer.
If is 0 then is true,if is >0 then is error etc…
Something like this

dim s as new sell s.mode=2 s.execute (ls -L) if s.errorcode =0 then "is ok" else msgbox "Failed.. " + Str(s.ErrorCode) end if
You can always use in shell 2 or more shell commands if you want.

s.execute (rsync -av --rsh=ssh host::module /dest;rsync -avFF --delete host:src/dir /dest)

the command above is just example.