Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: bat: Copy remote file & rename

Original Message
Name: Nivin37
Date: April 30, 2008 at 01:29:59 Pacific
Subject: bat: Copy remote file & rename
OS: XP
CPU/Ram: 2GHz/1GB
Comment:
Hi,
I need a batch file to do the following, however I do not have the knowledge, can anyone help?

1. Batch file to run every hour.

2. Copy file from remote PC on same subnet to local dir or dir on another remote PC.

3. Rename the file with the current date & time, keeping the extn (htm)


Though you might like the reason...

I Have a NASLite-2 server that keeps crashing every couple of days, it has a syslog that is not saved & a new one is generated each time the server is rebooted & you are unable to retrieve the syslog after the NASLite-2 server goes south. So in using the batch file I hope to find the u/s hardware & replace it.

Thanks in advance.


Report Offensive Message For Removal

Response Number 1
Name: klint
Date: April 30, 2008 at 03:48:32 Pacific
Subject: bat: Copy remote file & rename
Reply: (edit)
The following batch file copies the current file to a local folder and renames it to the current date and time:
__________________________________________________
@echo off
setlocal
set LocalFolder=C:\Logs
set RemoteFile=\\remotehost\C$\Logs\syslog.htm
set timestamp=%DATE:/=-%-%TIME:~0,2%%TIME:~3,2%
copy %RemoteFile% %LocalFolder%\%timestamp%.*
__________________________________________________

Note that you have to edit the above to use the correct folder and file names. Note that the time stamp has some characters removed (such as the colon) which are not allowed in file names.

To run this file every hour, create a scheduled task in Control Panel. Get it to run every day, then click Advanced before you click Finish, and change the "every day" to "every hour."


Report Offensive Follow Up For Removal

Response Number 2
Name: Nivin37
Date: April 30, 2008 at 14:55:19 Pacific
Subject: bat: Copy remote file & rename
Reply: (edit)
Hi klint,

Thanks for the answer, however I keep getting the following error,
---------
The syntax of the command is incorrect.
---------

Here is a copy of the file I used,
----------
@echo off
setlocal
set LocalFolder=C:\My Documents\Logs
set RemoteFile=\\Nas-01\Status\htm\syslog.htm
set timestamp=%DATE:/=-%-%TIME:~0,2%%TIME:~3,2%
copy %RemoteFile% %LocalFolder%\%timestamp%.*
---------------


Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: April 30, 2008 at 17:23:19 Pacific
Subject: bat: Copy remote file & rename
Reply: (edit)
You need to use quotes
copy "%RemoteFile%" "%LocalFolder%\%timestamp%.*"


Report Offensive Follow Up For Removal

Response Number 4
Name: klint
Date: May 1, 2008 at 01:37:03 Pacific
Subject: bat: Copy remote file & rename
Reply: (edit)
Thanks for that, Razor. I keep making the same mistakes when I give code samples to people. Of course, I tested the above and it worked on my machine - but that's because my pathnames did not contain any spaces. As soon as you've got spaces, you need to enclose in quotes. But I keep forgetting.

Report Offensive Follow Up For Removal

Response Number 5
Name: Nivin37
Date: May 1, 2008 at 14:52:18 Pacific
Subject: bat: Copy remote file & rename
Reply: (edit)
Thanks, klint & Razor2.3 all is working well.
I have a question, can I replace
set LocalFolder=...
with any folder on my subnet?

Thank again...


Report Offensive Follow Up For Removal

Response Number 6
Name: klint
Date: May 1, 2008 at 15:09:34 Pacific
Subject: bat: Copy remote file & rename
Reply: (edit)
Yes, no problem, LocalFolder is just used in the batch file as the destination of the copy command, so it doesn't necessarily have to be "local."

Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: bat: Copy remote file & rename

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC