Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

PsExec with XCOPY

I am trying to use psexec to copy a directory from remote machine to a network share. I've created a batch file with the following contents
Here is the command I use:

psexec \\remotecomputer xcopy "C:\TEST" "\\Server01\TEST SHARE\temp\TEST" /S /I /Y

that did not work but copying to another folder on the same machine as the one where source folder resids works:
psexec \\emotecomputer cmd /c xcopy "C:\TEST" "C:\AnotherFolder" /S /I /Y

I think it should work if I map the network share to a drive on the machine I am copying to, but the problem is that this batch will affect many different machines and I cannot map the network share on all of them. Is there a workaround?
Avatar of knightEknight
knightEknight
Flag of United States of America image

What error message does it show?
Do your account has rights to write to this share? PSEXEC usees account you've used to run it until -s or -p parameters are provided between remotecomputer and xcopy.
Avatar of YZlat

ASKER

does not show any error messages at all. Looks like it starts DOS prompt for a second and then it goes away


yes, my account (the account that I am logged in with) has rights to the share
Did you try with one file and cmd /c copy instead of xcopy?
Did you try to type your xcopy command on remote computer without using psexec?

It may give you some ideas about real cause of your problem...
Also, see if you can re-direct any output to a log file so you can see what's going on:

psexec \\remotecomputer xcopy /s /i /y  "C:\TEST"  "\\Server01\TEST SHARE\temp\TEST"  1>c:\cmd.out  2>c:\cmd.err
 

(the two log files will be on your local host)
Avatar of YZlat

ASKER

gtworek, I'll try cmd c/ copy instead

on the remote computer(locally) xcopy works fine (I don't need psexec in that case). The problem is that I need to run the command from the server to copy files from client computer to the network share.

knightEknight, thanks, I'll try that
Avatar of YZlat

ASKER

psexec \\remotecomputer cmd /c copy "C:\TEST" "\\Server01\TEST SHARE\temp\TEST" /S /I /Y

did not work - all it did is opened DOS prompt, ran psexec and then displayed

C:\WINDOWS\system32>
Avatar of YZlat

ASKER

knightEknight, I tried

psexec \\remotecomputer xcopy /s /i /y  "C:\TEST"  "\\Server01\TEST SHARE\temp\TEST"  1>c:\logfile.txt  2>c:\errorlog.txt

but both files were empty
psexec \\remotecomputer cmd /c copy "C:\TEST\*.*" "\\Server01\TEST SHARE\temp\TEST"

but it should not leave you with prompt...
Avatar of YZlat

ASKER

do I need \*.* after C:\TEST ?
for COPY - yes.
for XCOPY - it's not necessary.
Avatar of YZlat

ASKER

gtworek, I tried that and it opened DOS promp for a split second but I saw that it ran psexec and printed out "0 files copied" and one more line after that but the DOS prompt closes too fast and I can't read that line
0 doesn't sound good... ;)
If you replace /c with /k - your command should wait for you (for typing "exit") and you can read error messages:

psexec \\remotecomputer cmd /k copy "C:\TEST\*.*" "\\Server01\TEST SHARE\temp\TEST"
Avatar of YZlat

ASKER

OK, that worked:)

I got this

C:\TEST\*.* \\Server01\TEST SHARE\temp\TEST
The filename, directory name, or volume label syntax is incorrect
0 files copied
C:\WINDOWS\system32>
Do you use quotes?
Did you try with exactly same command locally? I cannot see what may be "incorrect" here...
Avatar of YZlat

ASKER

what do you mean by trying it locally?  just copy command without psexec?
Avatar of YZlat

ASKER

I logged in to a remote machine and ran this

cmd /k copy "C:\TEST\*.*" "\\Server01\TEST SHARE\temp\TEST"


got the same error :((
yes. maybe it's something wron with syntax...
Probably you should obtain working local command. If it's solved you can try to use it with psexec.
- Are you sure you are using backslashes not slashes in you command?
- maybe you can create share without space in the name?

have no idea what else may be wrong... it's just COPY command. Same since DOS 3.30... ;)
Avatar of YZlat

ASKER

I see what I did!

I typed extra double quote in

cmd /k copy "C:\TEST"\*.*" "\\Server01\TEST SHARE\temp\TEST"

so I removed it and ran

cmd /k copy "C:\TEST\*.*" "\\Server01\TEST SHARE\temp\TEST"

Now I got

C:\TEST\*.* The system cannot find the file specified
much much better :)
do you have c:\test?
do you have files in such directory?
Avatar of YZlat

ASKER

I have C:\TEST directory on remote computer specified in psexec command and inside the directory I have a folder with a number of files
so please test it with subfolder name included.

cmd /k copy "C:\TEST\SUBFOLDER\*.*" "\\Server01\TEST SHARE\temp\TEST"

You may also try with xcopy now.

copy cannot "look" into subfolder but xcopy can.
Avatar of YZlat

ASKER

got an error with copy:

C:\TEST\SUBFOLDER\test.db
Access is denied.
        0 file(s) copied.

I tried xcopy as well, but it closes DOS prompt too fast and I can't read the error
Do you have access rights to your subfolder content?
Does test.db is currently used (open) by another application?

"access denied" message gives us some new information...

you can try to copy files locally (i.e. from c:\test\subfolder to c:\test2) to see you have problem with reading or with writing your files.
Avatar of YZlat

ASKER


Now I added username and password:

psexec \\remotecomputer -u domain\username -p password xcopy "C:\TEST\" "\\Server01\TEST SHARE\temp\TEST" /S /I /Y
and got Invalid path error
xcopy exited with error code 4
System error 4 means "The system cannot open the file."
But I do not know xcopy uses same error codes...

You should reach perfectly working local command and then try to run it remotely. If you mix psexec with xcopy we cannot guess where is the issue located.
Avatar of YZlat

ASKER

xcopy "C:\TEST\" "\\Server01\TEST SHARE\temp\TEST" /S /I /Y
 works perfectly locally.

I ran it on the remotecomputer locally and it worked like a charm
So you may run psexec (just psexec) and obtain remote console. Then you can try copy&paste your perfectly working command and we will see what happens...
Avatar of YZlat

ASKER

I get the same error - Invalid drive specification
when I open psexec and then run:
xcopy "C:\TEST\" "\\Server01\TEST SHARE\temp\TEST" /S /I /Y

but if I run xcopy "C:\TEST\" "\C:\temp\TEST" /S /I /Y

then it copies the files
Have no idea... maybe it's some kind of xcopy issue...?
Can you try with robocopy instead of xcopy? I know it is next try but xcopy seems to fail... Robocopy has slightly different command syntax but possibilities are comparable with xcopy.
Avatar of YZlat

ASKER

The thing is I need to use the tools that are already on all the machines. Robocopy is not
oh yes... it's installed by default on newer systems only... psexec has "-c" switch to copy executables into target machine...
I'm looking for such strange solutions because I really do not know what happens with your xcopy...
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

hmmm, let me try that
Avatar of YZlat

ASKER

Brilliant! Thank you!
Avatar of YZlat

ASKER

oBdA, could you take a look at me other question? Perhaps you could help me there too...

https://www.experts-exchange.com/questions/24603796/Specifying-port-number-when-accessing-web-site.html