Moving Files over the network through a program

R

RussR

Hi,

What am I trying to achieve is to move a directory (or a set of files using
wildcards) from one computer on the network to another using a C++ program
The systems are running WindowsXP Professional. Permissions on each
directory is set to FULL for Everyone.

So for example, \\computerA runs a code that will move the directory,
\\computerB\\apps to c:\apps, where c:\apps is on computerA.

Here's where I got the line of code that I'm using to move files.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/movefileex.asp

void main() {

//here's the line of code that does the moving
int result= MoveFileEx("\\\\computerB\\apps","c:\\apps",
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING
MOVEFILE_WRITE_THROUGH);

//this is to print out the error message when it fails
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
printf("%s\n",lpMsgBuf);
// Free the buffer.
LocalFree( lpMsgBuf );
}

I get an error message usually saying access denied. Permissions are all
set full for everyone, so I'm stumped. If I change it to copy from one
directory on my computer to another directory on my computer, it only works
if the target directory doesn't already exist. If it does exist, I get an
access denied error....why? I've set all the MOVEFILE flags to avoid this.

Thanks,
RussR
 
R

RussR

Thanks for the response. You're right about MoveFileEx's limitation to the
same drive.

I posted here as I'm developing this on an xpe system which will be
headless...I thought folks here would have attempted similar things at some
point or another.


KM said:
RussR,

You should probably post this question to a Win32 dev newsgroup.

But anyway.. MoveFile[Ex] cannot move a directory to a different file
system or volume. When moving a directory, the destination must be on the
same drive.

You should use some other APIs to accomplish that. E.g., SHFileOperation
(shell32.dll must be in your XPe image if you further want to use the code
there).
http://msdn.microsoft.com/library/d...shell/reference/functions/shfileoperation.asp

--
Regards,
KM

Hi,

What am I trying to achieve is to move a directory (or a set of files
using
wildcards) from one computer on the network to another using a C++
program The systems are running WindowsXP Professional. Permissions on
each directory is set to FULL for Everyone.

So for example, \\computerA runs a code that will move the directory,
\\computerB\\apps to c:\apps, where c:\apps is on computerA.

Here's where I got the line of code that I'm using to move files.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/movefileex.asp

void main() {

//here's the line of code that does the moving
int result= MoveFileEx("\\\\computerB\\apps","c:\\apps",
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING
MOVEFILE_WRITE_THROUGH);

//this is to print out the error message when it fails
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
printf("%s\n",lpMsgBuf);
// Free the buffer.
LocalFree( lpMsgBuf );
}

I get an error message usually saying access denied. Permissions are all
set full for everyone, so I'm stumped. If I change it to copy from one
directory on my computer to another directory on my computer, it only
works
if the target directory doesn't already exist. If it does exist, I get
an
access denied error....why? I've set all the MOVEFILE flags to avoid
this.

Thanks,
RussR
 
R

RussR

Ok, I've got another question for you regarding LPSHFILEOPSTRUCT.
here's what I have:
LPSHFILEOPSTRUCT fileop;
fileop->hwnd= NULL;
fileop->wFunc=FO_MOVE;
fileop->pFrom=copyPath.c_str();
fileop->pTo="c:\\Data";
fileop->fFlags=FOF_SILENT | FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION;

I'm experiencing a problem in that hwnd is a pointer to a dialog window and
I don't know what to give it since my code is in a command line app. Any
ideas?

Thanks,
RussR
KM said:
RussR,

You should probably post this question to a Win32 dev newsgroup.

But anyway.. MoveFile[Ex] cannot move a directory to a different file
system or volume. When moving a directory, the destination must be on the
same drive.

You should use some other APIs to accomplish that. E.g., SHFileOperation
(shell32.dll must be in your XPe image if you further want to use the code
there).
http://msdn.microsoft.com/library/d...shell/reference/functions/shfileoperation.asp

--
Regards,
KM

Hi,

What am I trying to achieve is to move a directory (or a set of files
using
wildcards) from one computer on the network to another using a C++
program The systems are running WindowsXP Professional. Permissions on
each directory is set to FULL for Everyone.

So for example, \\computerA runs a code that will move the directory,
\\computerB\\apps to c:\apps, where c:\apps is on computerA.

Here's where I got the line of code that I'm using to move files.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/movefileex.asp

void main() {

//here's the line of code that does the moving
int result= MoveFileEx("\\\\computerB\\apps","c:\\apps",
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING
MOVEFILE_WRITE_THROUGH);

//this is to print out the error message when it fails
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
printf("%s\n",lpMsgBuf);
// Free the buffer.
LocalFree( lpMsgBuf );
}

I get an error message usually saying access denied. Permissions are all
set full for everyone, so I'm stumped. If I change it to copy from one
directory on my computer to another directory on my computer, it only
works
if the target directory doesn't already exist. If it does exist, I get
an
access denied error....why? I've set all the MOVEFILE flags to avoid
this.

Thanks,
RussR
 
K

KM

RussR,

Well.. In general the hwnd filed there is to provide the owner window handle.
However, you set the FOF_SILENT flag so it shouldn't be important to provide a valid window handle.

In case you'd need the progress dialog box, just pass in GetForegroundWindow() handle. In most case it works good enough.
(only exception may be if user start switching foreground window after the action was committed but before it really started).
Or use GetActiveWindow() (on Windows XP it should work even better).

--
Regards,
KM

Ok, I've got another question for you regarding LPSHFILEOPSTRUCT.
here's what I have:
LPSHFILEOPSTRUCT fileop;
fileop->hwnd= NULL;
fileop->wFunc=FO_MOVE;
fileop->pFrom=copyPath.c_str();
fileop->pTo="c:\\Data";
fileop->fFlags=FOF_SILENT | FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION;

I'm experiencing a problem in that hwnd is a pointer to a dialog window and I don't know what to give it since my code is in a
command line app. Any ideas?

Thanks,
RussR
KM said:
RussR,

You should probably post this question to a Win32 dev newsgroup.

But anyway.. MoveFile[Ex] cannot move a directory to a different file system or volume. When moving a directory, the destination
must be on the same drive.

You should use some other APIs to accomplish that. E.g., SHFileOperation (shell32.dll must be in your XPe image if you further
want to use the code there).
http://msdn.microsoft.com/library/d...shell/reference/functions/shfileoperation.asp

--
Regards,
KM

Hi,

What am I trying to achieve is to move a directory (or a set of files using
wildcards) from one computer on the network to another using a C++ program The systems are running WindowsXP Professional.
Permissions on each directory is set to FULL for Everyone.

So for example, \\computerA runs a code that will move the directory,
\\computerB\\apps to c:\apps, where c:\apps is on computerA.

Here's where I got the line of code that I'm using to move files.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/movefileex.asp

void main() {

//here's the line of code that does the moving
int result= MoveFileEx("\\\\computerB\\apps","c:\\apps",
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING MOVEFILE_WRITE_THROUGH);

//this is to print out the error message when it fails
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
printf("%s\n",lpMsgBuf);
// Free the buffer.
LocalFree( lpMsgBuf );
}

I get an error message usually saying access denied. Permissions are all
set full for everyone, so I'm stumped. If I change it to copy from one
directory on my computer to another directory on my computer, it only works
if the target directory doesn't already exist. If it does exist, I get an
access denied error....why? I've set all the MOVEFILE flags to avoid this.

Thanks,
RussR
 
R

RussR

Well I handed it Application, which is the Parent Window, but that really
wasn't the problem, here's what the problem is:
Notice my first line of code:
LPSHFILEOPSTRUCT fileop;
It shouldn't be LPSHFILEOPSTRUCT, it should be SHFILEOPSTRUCT as LP is a
pointer to a SHFILEOPSTRUCT. So I'm declaring a pointer and then proceeding
to do things like this:
fileop->hwnd= NULL;
fileop->wFunc=FO_MOVE;
fileop->pFrom=copyPath.c_str();
fileop->pTo="c:\\Data";
fileop->fFlags=FOF_SILENT | FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION;
None of which is in memory I own, hence the weird problems.

I needed to do:
SHFILEOPSTRUCT fileop;
fileop.hwnd=NULL;
fileop.wFunch=FO_MOVE;
..
..
And when I call shfileop, i need to give it &fileop.


KM said:
RussR,

Well.. In general the hwnd filed there is to provide the owner window
handle.
However, you set the FOF_SILENT flag so it shouldn't be important to
provide a valid window handle.

In case you'd need the progress dialog box, just pass in
GetForegroundWindow() handle. In most case it works good enough.
(only exception may be if user start switching foreground window after the
action was committed but before it really started).
Or use GetActiveWindow() (on Windows XP it should work even better).

--
Regards,
KM

Ok, I've got another question for you regarding LPSHFILEOPSTRUCT.
here's what I have:
LPSHFILEOPSTRUCT fileop;
fileop->hwnd= NULL;
fileop->wFunc=FO_MOVE;
fileop->pFrom=copyPath.c_str();
fileop->pTo="c:\\Data";
fileop->fFlags=FOF_SILENT | FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION;

I'm experiencing a problem in that hwnd is a pointer to a dialog window
and I don't know what to give it since my code is in a command line app.
Any ideas?

Thanks,
RussR
KM said:
RussR,

You should probably post this question to a Win32 dev newsgroup.

But anyway.. MoveFile[Ex] cannot move a directory to a different file
system or volume. When moving a directory, the destination must be on
the same drive.

You should use some other APIs to accomplish that. E.g., SHFileOperation
(shell32.dll must be in your XPe image if you further want to use the
code there).
http://msdn.microsoft.com/library/d...shell/reference/functions/shfileoperation.asp

--
Regards,
KM


Hi,

What am I trying to achieve is to move a directory (or a set of files
using
wildcards) from one computer on the network to another using a C++
program The systems are running WindowsXP Professional. Permissions on
each directory is set to FULL for Everyone.

So for example, \\computerA runs a code that will move the directory,
\\computerB\\apps to c:\apps, where c:\apps is on computerA.

Here's where I got the line of code that I'm using to move files.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/movefileex.asp

void main() {

//here's the line of code that does the moving
int result= MoveFileEx("\\\\computerB\\apps","c:\\apps",
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING
MOVEFILE_WRITE_THROUGH);

//this is to print out the error message when it fails
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
printf("%s\n",lpMsgBuf);
// Free the buffer.
LocalFree( lpMsgBuf );
}

I get an error message usually saying access denied. Permissions are
all
set full for everyone, so I'm stumped. If I change it to copy from one
directory on my computer to another directory on my computer, it only
works
if the target directory doesn't already exist. If it does exist, I get
an
access denied error....why? I've set all the MOVEFILE flags to avoid
this.

Thanks,
RussR
 
K

KM

RussR,
Well I handed it Application, which is the Parent Window, but that really wasn't the problem, here's what the problem is:
Notice my first line of code:
It shouldn't be LPSHFILEOPSTRUCT, it should be SHFILEOPSTRUCT as LP is a pointer to a SHFILEOPSTRUCT. So I'm declaring a pointer
and then proceeding to do things like this:

I had thought you just didn't show the whole code and you allocated the structed somewhere earleir in the code :)
I am glad you figured that out.

--
Regards,
KM
fileop->hwnd= NULL;
fileop->wFunc=FO_MOVE;
fileop->pFrom=copyPath.c_str();
fileop->pTo="c:\\Data";
fileop->fFlags=FOF_SILENT | FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION;
None of which is in memory I own, hence the weird problems.

I needed to do:
SHFILEOPSTRUCT fileop;
fileop.hwnd=NULL;
fileop.wFunch=FO_MOVE;
.
.
And when I call shfileop, i need to give it &fileop.


KM said:
RussR,

Well.. In general the hwnd filed there is to provide the owner window handle.
However, you set the FOF_SILENT flag so it shouldn't be important to provide a valid window handle.

In case you'd need the progress dialog box, just pass in GetForegroundWindow() handle. In most case it works good enough.
(only exception may be if user start switching foreground window after the action was committed but before it really started).
Or use GetActiveWindow() (on Windows XP it should work even better).

--
Regards,
KM

Ok, I've got another question for you regarding LPSHFILEOPSTRUCT.
here's what I have:
LPSHFILEOPSTRUCT fileop;
fileop->hwnd= NULL;
fileop->wFunc=FO_MOVE;
fileop->pFrom=copyPath.c_str();
fileop->pTo="c:\\Data";
fileop->fFlags=FOF_SILENT | FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION;

I'm experiencing a problem in that hwnd is a pointer to a dialog window and I don't know what to give it since my code is in a
command line app. Any ideas?

Thanks,
RussR

RussR,

You should probably post this question to a Win32 dev newsgroup.

But anyway.. MoveFile[Ex] cannot move a directory to a different file system or volume. When moving a directory, the
destination must be on the same drive.

You should use some other APIs to accomplish that. E.g., SHFileOperation (shell32.dll must be in your XPe image if you further
want to use the code there).
http://msdn.microsoft.com/library/d...shell/reference/functions/shfileoperation.asp

--
Regards,
KM


Hi,

What am I trying to achieve is to move a directory (or a set of files using
wildcards) from one computer on the network to another using a C++ program The systems are running WindowsXP Professional.
Permissions on each directory is set to FULL for Everyone.

So for example, \\computerA runs a code that will move the directory,
\\computerB\\apps to c:\apps, where c:\apps is on computerA.

Here's where I got the line of code that I'm using to move files.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/movefileex.asp

void main() {

//here's the line of code that does the moving
int result= MoveFileEx("\\\\computerB\\apps","c:\\apps",
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING MOVEFILE_WRITE_THROUGH);

//this is to print out the error message when it fails
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
printf("%s\n",lpMsgBuf);
// Free the buffer.
LocalFree( lpMsgBuf );
}

I get an error message usually saying access denied. Permissions are all
set full for everyone, so I'm stumped. If I change it to copy from one
directory on my computer to another directory on my computer, it only works
if the target directory doesn't already exist. If it does exist, I get an
access denied error....why? I've set all the MOVEFILE flags to avoid this.

Thanks,
RussR
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top