Transfer files from one server to another using batch script - windows

I have certain files in a folder on my local machine (Windows 8) and I want to transfer them to a remote server (Windows server 2012 R2) using a batch script.
Shown below is the script that I am trying to run but it throws an Invalid drive specification error. Note: I am sure that there is a folder called test in the specified location.
map.bat
xcopy /-y C:\Users\ssubburathinam\Documents\map1\*.* \\192.168.1.11\C:\Users\ssubburathinam\Desktop\test\ /d /c /y
pause
Screenshot of error
I do not know where to put my login credentials in this script as the remote server has login enabled. How can I accomplish this?

I recommend you to use the "Add a network location" in the main computer, so you can see a new drive letter with the network location. For your try, it might be wrong the share name on the remote computer, if you share a folder, usually is called by:
\\IP_or_name_of_the_remote_server\shared_name

Related

How to run a batch file in a remote machine from the Teamcity

I am building a C# project and deployed the package using Teamcity.
I have added a step in the build configuration that I need to execute a batch file present in the remote machine.
The batch file is copied to the remote machine along with the deployed package.
I am getting the error "The system cannot find the path specified."
If you are directly entering the path of the batch file, it will look for the same path on teamcity server and not on the remote machine.
you would have to install psexec on team city machine. See https://learn.microsoft.com/en-us/sysinternals/downloads/psexec
This command will help you to execute the script on remote machine
Now create a Command line step like this
and then in custom script use following :-
psexec \10.0.111.111 -d -accepteula -u domainname\userid -p password cmd.exe "Path/To/BatchFile.bat"
Here 10.0.111.111 is the ip adress of remote machine(Can use hostname as well).
domainname\userid is domain name and user id used to login the remote machine.
password is the password used to login remote machine.
Path/To/BatchFile.bat is the path to the batch file.

pscp network error: connection timed out

NOTE I am running on windows 10, not linux.
pscp.exe has been downloaded and run in my \Users\Taylor folder. I turned off my firewall just in case that could be interfering. I am trying to download files to my local windows from a remote linux environment using the following input to command prompt:
pscp user#quanah.hpcc.ttu.edu:/home/user/*.ctl \Downloads
I also varied the local name as such:
pscp user#quanah.hpcc.ttu.edu:/home/user/*.ctl C:\Users\Taylor\Downloads
This has worked perfectly in the past (~ one week ago), but now I get the error: "Fatal: Network error: Connection timed out" - I know the server (quanah.hpcc.ttu.edu) is connected and fine because I can ssh to it via PuTTY. Any recommendations?
I'd make sure that once I get the dos shell going, I navigate to where pscp.exe is located and run your command from there, i.e.:
C:\Users\Taylor>pscp ...
I'd also go to the source directory on quanah.hpcc.ttu.edu, in your case, '/home/user/' and do 'pwd' to confirm full path
I'd also set my target directory to be where pscp.exe is located i.e. C:\Users\Taylor because I've had success with that; and not because that is the only way.

Automating an installation using BAT/PS scripts

I have been attempting to automate the installation of one of my applications but have run into a few roadblocks and I really need some help.
Currently we are using Dell's KACE technology to push the installer to the local machines. The installer is run as the SYSTEM user meaning it does not and can not have direct access to network shares (relevant later).
The application installation workflow is as follows:
Stop Local Security Services to allow software install
Remove anything mapped to drive letter X
Map network drive X \test\test
TestApp.exe /s
msiexec /i Test.msi /quiet
Start Local Security Services to allow software install
copy shortcut file to desktop
The installation itself has 1 Executable and 1 MSI that have to be run. The EXE installs a mainframe application. The MSI file installs a few files locally and then registers 6 DLL files located on that mapped drive.
This is where the issue comes in - Because those files MUST be on that share drive and the installer is running as SYSTEM -> The System account account can't access the mapped drive to register the files so the installation fails.
I am further limited by the fact that I can't simply store a username/password in plaintext in the batch file.
Here is my code so far:
REM Stopping McAfee Services
echo Stopping McAfee Services.
net stop mcshield
net stop mcafeeframework
REM Map Network Drive
echo Mapping Network Drive
net use X: /delete /y
net use X: \\test\test
(Here is where I need help - Is there a way to force a username/password prompt here for the user? I basically just want the user to authenticate to the X drive mapping, which will allow the installation to move forward)
echo Starting Test 1 Installation
Test1.exe /s /v"/qb"
echo Starting Test 2 Installation
msiexec /i Test2.msi /quiet
(If the drive has not been mapped by this point, the installation fails as the SYSTEM account can't access the drive)
echo.
REM Restarting Mcafee Services
echo Starting McAfee Services.
net start mcshield
net start mcafeeframework
echo.
REM Copy Shortcut
xcopy "shortcut\*" "C:\Users\public\desktop"
Alternatively,
Could/should I convert this to a PS script? I know PS is more powerful than batch, but wasn't sure how to go about it.
If by forcing authentication prompt, you mean something that will need human input (and you aren't running this script remotely), then this line should interact with existing login session and ask for credentials:
start explorer \\test\test
echo After you have entered network credentials
pause
Once user enters valid ones, the remaining script can continue
net use X: \\test\test
After toying with ideas about this problem for a couple of weeks I decided to take a new approach.
I created a new batch file using a simple NET USE and passed the credentials of a service account w/ access to the network share in plain text. Next, I compiled the batch into an executable. It's not the most elegant solution out there I'm sure, but it's sufficient for our needs currently.
Thanks for the help everyone!

How to run remote bat file without prompt

I have a remote drive mapped to my local Z:\ drive.
When running using this:
System.Diagnostics.Process.Start("Z:\\Test.bat");
It opens a prompt as to whether or not to open the file. How do I disable this setting in windows or get around it using c#?

how to use xcopy to append to a file in remote machine?

I am using psexec to connect to remote windows machine and xcopy to copy few files and run the batch files present in remote machine. However the xcopy overwrites the contents of the file in the remote machine. How to use xcopy or something similar to append to files in the remote windows machine?
Or is it possible to copy a file from remote windows machine to local using xcopy or similar?
Note : the remote machine is windows and not running either ftp or any other service.
Thanks
Nohsib
Have a look at Robocopy - http://ss64.com/nt/robocopy.html
It is the Windows equivalent of Rsync.
You could try PowerShell 2.0 remoting. Should fit most of your needs.

Resources