forked from Johnng007/NetCopy-Copy-Files-Across-the-Network
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkCopy.bat
More file actions
416 lines (348 loc) · 13.7 KB
/
NetworkCopy.bat
File metadata and controls
416 lines (348 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
:: ==================================================================================
:: NAME : Copy Files Across The Network.
:: AUTHOR : Ebuka John Onyejegbu.
:: CONTACT : onyejegbujohne@gmail.com
:: VERSION : 1.0.
:: ==================================================================================
:: Screen settings.
:: /************************************************************************************/
:mode
echo off
title NetCopy.
color 47
goto permission
:: /************************************************************************************/
:: Print Top Text.
:: /*************************************************************************************/
:print
cls
echo.
echo.NetCopy - Move Files Accross the Network.
echo.
echo.%*
echo.
goto :eof
:: /************************************************************************************/
:: Checking for Administrator elevation.
:: /************************************************************************************/
:permission
openfiles>nul 2>&1
if %errorlevel% EQU 0 goto terms
call :print Checking for Administrator elevation.
echo. You are not running as Administrator.
echo. This batch cannot do it's job without elevation.
echo.
echo. You must run this tool as Administrator.
echo.
echo.Press any key to continue . . .
pause>nul
goto :eof
:: /************************************************************************************/
:: Terms.
:: /*************************************************************************************/
:terms
call :print Terms and Conditions.
echo. The methods inside this batch copies files/Folders securely across the network.
echo. This batch is coded by Ebuka John Onyejegbu.
echo. onyejegbujohne@gmail.com
echo.
echo. NOTE: batch files are almost always flagged by anti-virus.
echo.
choice /c YN /n /m "Do you want to continue with this process? (Yes/No) "
if %errorlevel% EQU 1 goto Menu
if %errorlevel% EQU 2 goto Close
echo.
echo.An unexpected error has occurred.
echo.
echo.Press any key to continue . . .
pause>nul
goto :eof
:: /*************************************************************************************/
:: Menu of tool.
:: /*************************************************************************************/
:Menu
call :print Main menu.
echo. FOLDER SHARING
echo. 1. Copy Folders from This PC To Another.
echo. 2. Copy Folders from a Remote PC to another.
echo FILE SHARING
echo. 3. Copy Files from This PC To Another.
echo. 4. Copy Files from a Remote PC to another.
echo MASS COPY
echo 5. Copying Folders from one PC to Many PCs.
echo PRINTER SHARING
echo 6. Connect a remote PC to a Printer (BETA)
echo. 7. Close.
echo.
set /p option=Select option:
if %option% EQU 1 (
call :Copy1
) else if %option% EQU 2 (
call :Copy2
) else if %option% EQU 3 (
call :Copy3
)else if %option% EQU 4 (
call :Copy4
)else if %option% EQU 5 (
call :Copy5
)else if %option% EQU 6 (
call :Copy6
)else if %option% EQU 7 (
goto Close
) else (
echo.
echo.Invalid option.
echo.
echo.Press any key to continue . . .
pause>nul
)
goto Menu
:: /*************************************************************************************/
:: Copying Folders from your PC to another PC.
:: /*************************************************************************************/
:Copy1
call :print Setting up Folder transfer parameters
SETLOCAL EnableDelayedExpansion
SET /P "TerminalName=Enter the IP Address of the PC you wish to copy Folders to: "
ECHO Do you wish to copy Folders to this PC !TerminalName! ?
ECHO NOTE: Folders will be copied to the c:\NETSHARE of this PC
PAUSE
SET /P "FilePath=Enter the path to the Folder you wish to copy e.g C:\CLIENT\OFFICE: "
ECHO Do you wish to copy this Folder: !FilePath! ?
PAUSE
SET "SourcePath=!FilePath!"
SET "TargetPath=\\!TerminalName!\C$\"
IF NOT EXIST "!TargetPath!" (
call :print Target PC is unreachable, make sure its on network.
echo.Press any key to continue . . .
pause>nul
goto :eof
)
ECHO Target PC has been reached!
ECHO Copying Folders! Here we go...
IF EXIST "%TargetPath%\NETSHARE" (
ECHO The NETSHARE folder already exists..
) ELSE (
ECHO No NETSHARE Folder exists... Let's sort that out!
MKDIR "%TargetPath%\NETSHARE"
IF ERRORLEVEL 1 (
call :print Failed to create NETSHARE folder "%TargetPath%\NETSHARE".
echo.Press any key to continue . . .
pause>nul
goto :eof
)
)
ECHO ECHO Copying files now ...
robocopy "%SourcePath%\*" "%TargetPath%\NETSHARE" /e
call :print The Folder was moved successfully.
echo.Press any key to continue . . .
pause>nul
goto :eof
:: /*************************************************************************************/
:: Copying Folders from a Remote PC to Another Remote PC.
:: /*************************************************************************************/
:Copy2
call :print Setting up Folder transfer parameters
SETLOCAL EnableDelayedExpansion
SET /P "SourceTerminalName=Enter the IP Address of the PC you wish to copy Folders from: "
ECHO Do you wish to copy Folders from this PC: !SourceTerminalName! ?
PAUSE
SET /P "DestinationTerminalName=Enter the IP Address of the PC you wish to copy Folders to: "
ECHO Do you wish to copy Folders to this PC: !DestinationTerminalName! ?
ECHO NOTE: Folders will be Copied to the c:\NETSHARE of this PC
PAUSE
SET /P "SourceFilePath=Enter the path to the Folder on the Source PC you wish to copy e.g Users\Ebuka\Pictures:"
ECHO Do you wish to copy this Folder: !SourceFilePath! ?
PAUSE
SET "SourcePath=\\!SourceTerminalName!\c$\!SourceFilePath!"
SET "TargetPath=\\!DestinationTerminalName!\c$\NETSHARE"
IF NOT EXIST "!TargetPath!" (
call :print Target PC is unreachable, make sure its on network.
echo.Press any key to continue . . .
pause>nul
goto :eof
)
ECHO Target PC has been reached!
ECHO Copying files! Here we go...
IF EXIST "%TargetPath%\NETSHARE" (
ECHO The NETSHARE folder already exists..
) ELSE (
ECHO No NETSHARE Folder exists... Let's sort that out!
MKDIR "%TargetPath%\NETSHARE"
IF ERRORLEVEL 1 (
call :print Failed to create NETSHARE folder "%TargetPath%\NETSHARE".
echo.Press any key to continue . . .
pause>nul
goto :eof
)
)
ECHO Copying files now ...
robocopy "%SourcePath%\*" "%TargetPath%\NETSHARE\" /e
call :print The Folder was copied successfully.
echo.Press any key to continue . . .
pause>nul
goto :eof
:: /*************************************************************************************/
:: FILE SHARING
:: /*************************************************************************************/
:: /*************************************************************************************/
:: Copying files from your PC to another PC.
:: /*************************************************************************************/
:Copy3
call :print Setting up file transfer parameters
SETLOCAL EnableDelayedExpansion
SET /P "TerminalName=Enter the IP Address of the PC you wish to copy files to: "
ECHO Do you wish to copy files to this PC !TerminalName! ?
ECHO NOTE: Files will be copied to the c:\NETSHARE of this PC!
PAUSE
SET /P "FilePath=Enter the path to the file you wish to copy e.g C:\CLIENT\JAVA"
ECHO Do you wish to copy a file in this Folder: !FilePath! ?
PAUSE
SET /P "File=Enter the file name you wish to copy e.g java8u28.exe: "
ECHO Do you wish to copy this Folder: !File! ?
PAUSE
SET "SourcePath=!FilePath!"
SET "TargetPath=\\!TerminalName!\C$\"
SET "SourceFile=!File!"
IF NOT EXIST "!TargetPath!" (
call :print Target PC is unreachable, make sure its on network.
echo.Press any key to continue . . .
pause>nul
goto :eof
)
ECHO Target PC has been reached!
ECHO Copying files! Here we go...
IF EXIST "%TargetPath%\NETSHARE" (
ECHO The NETSHARE folder already exists..
) ELSE (
ECHO No NETSHARE Folder exists... Let's sort that out!
MKDIR "%TargetPath%\NETSHARE"
IF ERRORLEVEL 1 (
call :print Failed to create NETSHARE folder "%TargetPath%\NETSHARE".
echo.Press any key to continue . . .
pause>nul
goto :eof
)
)
ECHO Copying files now ...
robocopy "%SourcePath%\*" "%TargetPath%\NETSHARE" %SourceFile%
call :print The File was copied successfully.
echo.Press any key to continue . . .
pause>nul
goto :eof
:: /*************************************************************************************/
:: Copying Files from a Remote PC to Another Remote PC.
:: /*************************************************************************************/
:Copy4
call :print Setting up file transfer parameters
SETLOCAL EnableDelayedExpansion
SET /P "SourceTerminalName=Enter the network path to the file you wish to copy: e.g \\127.0.0.1\c$\CLIENT"
ECHO Do you wish to copy files from this PC: !SourceTerminalName! ?
PAUSE
SET /P "DestinationTerminalName=Enter the IP Address of the PC you wish to move files to: "
ECHO Do you wish to copy files to this PC: !DestinationTerminalName! ?
ECHO NOTE: Files will be moved to the c:\NETSHARE of this PC
PAUSE
SET /P "SourceFile=Enter the file name you wish to copy e.g java8u28.exe: "
ECHO Do you wish to copy this Folder: !File! ?
PAUSE
SET "SourcePath=!SourceTerminalName!"
SET "TargetPath=\\!DestinationTerminalName!\c$\"
SET "SourceFile=!File!"
IF NOT EXIST "!TargetPath!" (
call :print Target PC is unreachable, make sure its on network.
echo.Press any key to continue . . .
pause>nul
goto :eof
)
ECHO Target PC has been reached!
ECHO Copying files! Here we go...
IF EXIST "%TargetPath%\NETSHARE" (
ECHO The NETSHARE folder already exists..
) ELSE (
ECHO No NETSHARE Folder exists... Let's sort that out!
MKDIR "%TargetPath%\NETSHARE"
IF ERRORLEVEL 1 (
call :print Failed to create NETSHARE folder "%TargetPath%\NETSHARE".
echo.Press any key to continue . . .
pause>nul
goto :eof
)
)
ECHO Copying files now ...
robocopy "%SourcePath%\*" "%TargetPath%\NETSHARE\" %SourceFile%
call :print The File was copied successfully.
echo.Press any key to continue . . .
pause>nul
goto :eof
:: /*************************************************************************************/
:: MASS COPY
:: /*************************************************************************************/
:: /*************************************************************************************/
:: Copying Folders from one PC to Many PCs.
:: /*************************************************************************************/
:Copy5
call :print Setting up Folder transfer parameters
SETLOCAL EnableDelayedExpansion
SET /P "PCList=Enter the PC List Path e.g \\127.0.0.1\c$\PCList\List.txt: "
ECHO Do you wish to use this list: !PCList! ?
PAUSE
SET /P "DeploymentKit=Enter the Path to the Deployment Folder e.g \\127.0.0.1\c$\UPDATE: "
ECHO Do you wish to deploy this Folder: !DeploymentKit! ?
PAUSE
SET /P "LogPath=Enter the path to where you wish to log successful/failed attempts e.g \\127.0.0.1\c$\LOGS"
ECHO Do you wish to use this path: !LogPath! ?
PAUSE
SET "PCListPath=!PCList!"
SET "DeployKit=!DeploymentKit!"
SET "LogsPath=!LogPath!"
ECHO Copying files now ...
cls
For /F "usebackq tokens=*" %%a in ("%PCListPath%") Do (
COPY "%DeployKit%" "\\%%a\C$\NETSHARE" /y &&(
>>%LogsPath%\success.txt echo.%%a
) ||(
>>%LogsPath%\failure.txt echo.%%a
)
)
pause>nul
goto :eof
:: /*************************************************************************************/
:: PRINTER SHARING
:: /*************************************************************************************/
:: /*************************************************************************************/
:: Connect a remote PC to a remote USB Connected Printer (BETA)
:: The Printer should be shared on the PC its connected to
:: /*************************************************************************************/
:Copy6
call :print Setting up printer sharing parameters
SETLOCAL EnableDelayedExpansion
SET /P "SourceTerminalName=Enter the Host printer share path e.g \\10.51.21.45\HOMEPRINTER: "
ECHO We would assume this contains the PC IP address and shared printer Name !SourceTerminalName! ?
PAUSE
SET /P "DestinationTerminalName=Enter the Proposed Destination printer share path e.g \\10.51.22.70\HOMEPRINTER: "
ECHO Do you wish to use this file path !DestinationTerminalName! ?
PAUSE
SET "SourcePath=!SourceTerminalName!"
SET "TargetPath=!DestinationTerminalName!"
REM add the specified printer to the specified computer
@Echo On
rundll32 printui.dll,PrintUIEntry /ga /c%TargetPath% /n%SourcePath%
@Echo off
REM stop the print spooler on the specified computer and wait until the sc command finishes
@Echo On
start /wait sc %TargetPath% stop spooler
@Echo off
REM start the print spooler on the specified computer and wait until the sc command finishes
@Echo On
start /wait sc %TargetPath% start spooler
call :print The Printer installed successfully, Please check Devices & Printers.
echo.Press any key to continue . . .
pause>nul
goto :eof
:: /*************************************************************************************/
:: End tool.
:: /*************************************************************************************/
:close
exit
:: /*************************************************************************************/