-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessAndSendTheFile-<client>-<carrier>.bat
105 lines (86 loc) · 3.17 KB
/
ProcessAndSendTheFile-<client>-<carrier>.bat
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
@echo off
REM This batch file will be run from the same directory as the file that you need to PGP.
SETLOCAL
REM TODO - validate return codes.
REM TODO - dynamic client and carrier
REM TODO - more dynamic filenames
REM TODO - run from any directory
REM TODO - better comments. And actually DO the TODOs.
REM Set default variables.
SET defaultSourceKey=0xA123456A
SET defaultDestinationKey=0xA654321A
SET theClient="Client Name"
SET theCarrierCode="Carrier_Coverage"
SET currentFileName="testFile_DATE.txt"
SET finalFileName="testfile.txt"
SET pgpFileName="testfile.txt.pgp"
REM Initial Run through and retry for file name.
:tryAgain
CLS
REM Reset filename to default
SET filename=
REM Prompt for the file name to PGP.
SET /p filename=Please enter the File Name to PGP:
REM Check to see if the file exists in the current directory.
IF EXIST "%filename%" (
REM If the file exists, pgp it.
GOTO :checkPgpKey
) ELSE (
REM If the file doesn't exist, do you want to retry?
ECHO Oops. The file that you wanted to encrypt doesn't exist. Is this batch file in the same directory as the file you want to encrypt?
GOTO :wantToTryAgain
)
:checkPgpKey
REM Prompt to enter a PGP key if you don't want to use the defaultDestinationKey.
SET pgpKey=%defaultDestinationKey%
SET /p pgpKey=Please enter the PGP Key (Default is %theClient% - %theCarrierCode%):
REM Check to see if entered key is a valid Hex key for PGP.
SET /a pgpKeyVal="%pgpKey%"*1
IF "%pgpKeyVal%" == "0" (
ECHO Please enter a valid hex encryption key.
GOTO :checkPgpKey
) ELSE (
GOTO :copyFileName
)
:copyFileName
ECHO Copying %filename% to %currentFileName%
SET exportFile=
COPY /Y %filename% %finalFileName%
SET exportFile=%finalFileName%
GOTO :runPGP
:runPGP
ECHO Beginning PGP process on %exportFile% with a key of %pgpKey%.
REM All was good. Call PGP.
x:\Automation\gpg\gpg --homedir "\\nas\files\Automation\gpg" --recipient %defaultSourceKey% --recipient %pgpKey% --output "%pgpFileName%" --yes --encrypt "%exportFile%"
ECHO PGP Complete.
GOTO :wantToSendToFTP
:wantToSendToFTP
SET /P qSendToFTPYN=Do you want to send to the %theCarrierCode% FTP (Y/N)?
IF /i {%qSendToFTPYN%}=={y} (GOTO :sendToFTP)
IF /i {%qSendToFTPYN%}=={yes} (GOTO :sendToFTP)
GOTO :encryptAnother
:sendToFTP
REM We have to change the filename. We are deleting the last file and renaming the file we need to pgp and send.
ECHO Deleting Original Name.
DEL %pgpFileName%
ECHO Renaming file for FTP send.
REN %pgpFileName% %exportFile%
ECHO Sending file to FTP.
x:\Automation\WinSCP\WinSCP.exe \WinSCP\winscp.com /ini=x:\Automation\WinSCP\WinSCP.ini /log=WinSCP_%theCarrierCode%.log /command "option batch abort" "option confirm off" "open ftp://user:[email protected]" "put %exportFile%" "exit"
ECHO File sent.
GOTO :encryptAnother
:encryptAnother
SET /P qEncryptAnotherYN=Do you want to encrypt another file (Y/N)?
IF /i {%qEncryptAnotherYN%}=={y} (GOTO :tryAgain)
IF /i {%qEncryptAnotherYN%}=={yes} (GOTO :tryAgain)
GOTO :bailOut
:wantToTryAgain
SET /P qTryAgainYN=Do you want to try again (Y/N)?
IF /i {%qTryAgainYN%}=={y} (GOTO :tryAgain)
IF /i {%qTryAgainYN%}=={yes} (GOTO :tryAgain)
GOTO :bailOut
:bailOut
ECHO Goodbye.
REM EXIT /b 1
ENDLOCAL
TIMEOUT /t 10