Command line to copy files from remote location - windows

I want to write a script that will copy some files from LAN computer to my pc. I don't know what would be the syntax of this command.
Could anyone help me related to this?
One thing more, that in my case both the machines are using Windows.

xcopy /z \\myServer\myFolder c:\
/Z Copies networked files in restartable mode.
where \myServer\myFolder is a unc path , or if you have network drive ( for example o:) so use :
xcopy /z o: c:\

net.exe use to map remote share to temporary drive letter
copy or robocopy or xcopy or whever to copy the files
net.exe use to remove used mapping and free the letter
Note that Windows (95/98/ME) and WindowsNT ( NT3 / NT$ / 2000 / XP / Vista / 7) are radically different operating systems and have different DOS commands and options, especialy regarding copying.

Related

Copy files from One Server to Another Server using Batch Command - Windows machine

How to copy files from one server to another server(VM) using a windows batch command. ?
I have used below command
syntax : xcopy \\source_path \\serverIP\Destination_path /s /a /d
example : xcopy \\c:\repo\testproject \\10.101.101.11\C:\test\project /s /a /d
I'm getting the below error "Invalid drive specification" as of now.
Do I need to give credentials for accessing the VM ? If yes then where and how?
I have checked the destination path is correct.
Is there any other command should be used in that case ?
Do I need to give credentials for accessing the VM ? If yes then where and how?
If the passwords on the source and target machine are the same then no credentials are necessary, otherwise yes they will need to be provided. Two solutions you can consider:
Use "runas" and specify the credentials there
Use the temporary network drive solution proposed in the comment by UserPo41085. This solution uses the "net view" command which has credential parms.
I have checked the destination path is correct.
example : xcopy \\c:\repo\testproject \\10.101.101.11\C:\test\project /s /a /d
Both paths in the example provided are a mixture of standard "DOS" paths and UNC paths. UNC paths reference a share name and not a disk letter.
The example in the link below copies a file on the local machine called zz_yuv.png to a machine called "ws9" which has a share called "c9.system" and the share is mapped to the root folder of the c: drive on ws9. If you are running an account which is a member of the administrators group you can use the admin shares...(admin$, c$ etc.)
xcopy example
Is there any other command should be used in that case ?
Robocopy is built into the later versions of windows. It does come with a learning curve but is much more robust than xcopy. Just as a note, robocopy will be under the same types of credentialing restraints as xcopy - it just has more and better features for copying.

What is the location of FINDSTR on all Windows OS from Windows XP to Windows server 2012?

Is the directory of findstr always C:\Windows\system32\ for all OS from Windows XP to server 2012?
Or in other words is it safe to replace the following expression in a windows batch file:
findstr
to
C:\Windows\system32\findstr
Extra information just for completeness.
Environment variable windir exists since Windows 95 and contains the path to Windows directory independent on which drive it is located and which name it has.
For NT based Windows (NT4, Windows 2000, Windows XP, Vista, Windows 7 / 8 / 8.1) there is additionally the environment variable SystemRoot which contains also the path to Windows directory as this is the parent directory for the system directories
System32
Sysnative (only Windows x64 and only for 32-bit applications)
SysWOW64 (only Windows x64)
For details about file system redirection read the File System Redirector page of Microsoft.
It is not only safe to use either
%windir%\System32\findstr.exe
or
%SystemRoot%\System32\findstr.exe
I would highly recommend using always one of those two strings in batch files as then it does not depend which folders are in environment variable PATH and which file extensions in environment variable PATHEXT.
There are some bad installers which add the folder path of the installed application to system environment variable PATH at beginning instead of appending at end and contain in the application's folder also find.exe or findstr.exe which are portings from Unix and therefore work completely different than find.exe and findstr.exe of Windows. AVRStudio is (or perhaps was as not verified with latest version of AVRStudio) an example breaking batch files of IT administrators not using always complete file name for Windows commands after installation.
Rather %windir%\system32\findstr.exe as its possible windows to be installed on different than C:\ drive.
I am afraid I don't understand the purpose of your question, so I rephrase it in a slightly different way.
If you type findstr in a computer and the FINDSTR command run, then you may know the location of such findstr command this way:
for %%a in (findstr.exe) do echo %%~$PATH:a
So you may replace the following expression:
findstr
... by the next two lines:
for %%a in (findstr.exe) do set "findstrPath=%~$PATH:a"
%findstrPath%
... in a Windows Batch file and you will get exactly the same result.
So, the question arises: if you get the same result in both cases, why do you want to use the second, more complicated one?
Note also that the same point apply with any other external command like find, xcopy, forfiles, etc. Why findstr would be special in this point?
As I said before, I don't understand the purpose of your question...

Copy files to network computers on windows command line

I am trying to create a script on Windows which when run on an admin PC:
Copies a folder from the admin PC into a group of network PCs by specifying the ip address / range
For each destination PC, Navigate into the folder and run another script file.
Using the method described by seanyboy here:
net use \\{dest-machine}\{destfolder} {password} /user:{username}
copy {file} \\{dest-machine}\{destfolder}
I'm not sure on how i can write a 'for' loop to go through each 'dest-machine' and perform step 2. Any ideas would be greatly appreciated.
check Robocopy:
ROBOCOPY \\server-source\c$\VMExports\ C:\VMExports\ /E /COPY:DAT
make sure you check what robocopy parameter you want. this is just an example.
type robocopy /? in a comandline/powershell on your windows system.
Below command will work in command prompt:
copy c:\folder\file.ext \\dest-machine\destfolder /Z /Y
To Copy all files:
copy c:\folder\*.* \\dest-machine\destfolder /Z /Y
Why for? What do you want to iterate? Try this.
call :cpy pc-name-1
call :cpy pc-name-2
...
:cpy
net use \\%1\{destfolder} {password} /user:{username}
copy {file} \\%1\{destfolder}
goto :EOF
Regarding step 2., check manual for psexec command (sysinternal tools)

Batch file to copy files from one directory to another

I have two code bases of an application. I need to copy all the files in all the directories with .java from the newer code base, to the older (so I can commit it to svn).
How can I write a batch files to do this?
XCOPY /D ?
xcopy c:\olddir\*.java c:\newdir /D /E /Q /Y
If you've lots of different instances of this problem to solve, I've had some success with Apache Ant for this kind of copy/update/backup kind of thing.
There is a bit of a learning curve, though, and it does require you to have a Java runtime environment installed.
I like Robocopy ("Robust File Copy"). It is a command-line directory replication command. It was available as part of the Windows Resource Kit, and is introduced as a standard feature of Windows Vista and Windows Server 2008.

Copying from network share using BAT

What's the best way to copy a file from a network share to the local file system using a Windows batch file? Normally, I would use "net use *" but using this approach how can I get the drive letter?
Can you just use the full UNC path to the file?
copy \\myserver\myshare\myfolder\myfile.txt c:\myfiles
You can specify the drive letter for net use. Put this in the command prompt for more info:
net use /?
You can also use xcopy and robocopy:
xcopy "\\server\share\path" "destination"
robocopy "\\server\share\path" "destination"

Resources