9772885
asked on
C++ CopyFile UNC Failure
I have been trying to copy a file fom my local drive to a UNC path but it doesnt copy, it works if i try to copy from local to local but not to s server
ive tried doubling up the back slashes etc like the below
\\\\?\\UNC\\
does anyone have any further information on this?
ive tried doubling up the back slashes etc like the below
\\\\?\\UNC\\
does anyone have any further information on this?
You must make sure that you share the directory and set the path/file access security on the remote directory to allow you read write and create access. This usually means that you have to add a user group or "Anyone" to the access privledge list and set the appropriate check boxes corresponding to the privledge level you want to assign.
What does 'GetLastError()' return?
ASKER
Im very new to C++ so havnt learnt much yet and im not sure how to apply the function you have suggested. I am able to create new files in the destination folder if i open in explorer so shouldnt be a permissions problem
/*Refresh Control*/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <windows.h>
#include <cstdlib>
#include <istream>
#include <iterator>
#include <fstream>
using namespace std;
int main ()
{
// declare a variable
int i;
int j;
for(i= 0; i < 1; i=0)
{
int i;
printf ("Checking if processor is available...");
if (system(NULL)) puts ("Ok");
else exit (1);
printf ("Executing Refresh...\n");
i = system ("c:/folder/Refresh.acsaut o");
printf ("RC: %d.\n",i); //Display Return Code
for(int i=0; i<300000000;i++); //Wait For 5 Seconds
printf ("Wait Finished");
//Copy File
CopyFile("C:\\Plasma\\ACD_ Primary.tx t", "\\\\?\\UNC\\Server\\Folde r\\Output. txt",1);
}
return 0;
MessageBox(NULL, "An Error Has Occured", "An Error Has Occured", MB_OK);
}
/*Refresh Control*/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <windows.h>
#include <cstdlib>
#include <istream>
#include <iterator>
#include <fstream>
using namespace std;
int main ()
{
// declare a variable
int i;
int j;
for(i= 0; i < 1; i=0)
{
int i;
printf ("Checking if processor is available...");
if (system(NULL)) puts ("Ok");
else exit (1);
printf ("Executing Refresh...\n");
i = system ("c:/folder/Refresh.acsaut
printf ("RC: %d.\n",i); //Display Return Code
for(int i=0; i<300000000;i++); //Wait For 5 Seconds
printf ("Wait Finished");
//Copy File
CopyFile("C:\\Plasma\\ACD_
}
return 0;
MessageBox(NULL, "An Error Has Occured", "An Error Has Occured", MB_OK);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ive made that change and set up a test script to try and get the copy to work but its still not copying across, there wasnt a file to overwrite so the old code should still have worked. Do i have this set correctly is there a way to check if there is an error it seems to run through with no problems, should there be a return code i can check?
#include <windows.h>
int main ()
{
//Copy File
CopyFile("C:\\Plasma\\ACD_
}
To check for errors, you could do the following:
#include <windows.h>
#include <stdio.h>
int main ()
{
//Copy File
BOOL bRC = CopyFile("C:\\Plasma\\ACD_Primary.txt", "\\\\?\\UNC\\Server\\Folder\\Output.txt",0);
if (!bRC) printf("Error: %d\n", GetLastError());
}
ASKER
I have now tried this, a blank cmd box briefly pops up for a few secinds and then disapears with no error msge and nor is the file copied accross
In that case, try the following, so the error should be readable:
#include <windows.h>
#include <stdio.h>
int main ()
{
//Copy File
BOOL bRC = CopyFile("C:\\Plasma\\ACD_Primary.txt", "\\\\?\\UNC\\Server\\Folder\\Output.txt",0);
if (!bRC) printf("Error: %d\n", GetLastError());
Sleep(20000);
}
ASKER
Hi there was no error message just a blank screen
If there was no error message, the file should have been copied successfully...
ASKER
It is now working thank you all for your help.