-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreciveftp.bat
162 lines (145 loc) · 4.48 KB
/
reciveftp.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
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
@echo off
title RECIVER
if exist curl.exe (
goto curlpathsetb
) else (
set curlpath=curl
echo is recommended to have the curl provided.
pause
goto inic
)
rem to fix a if () bug
:curlpathsetb
set "curlpath=%~dp0curl.exe"
echo %curlpath% set
goto inic
:inic
cd users
:o
echo catching the user
if not exist reciverin.l (
echo waiting for reciverin.l
echo waiting for reciver_filename.l0
timeout /t 1 > nul
goto o
) else (
set /p user=<reciverin.l
set /p filename_save=<reciver_filename.l
del reciverin.l
del reciver_filename.l
goto sender
)
:sender
echo %user%
echo wip
cd %user%
set /p username=<username
set /p password=<password
set /p server=<server
echo %filename_save%
echo %username%
echo %password%
echo %server%
echo setting the protocol mode
set /p sftpmode=<sftp
if EXIST sftp (
set sftpmode=sftp
goto loop2
) else (
set sftpmode=ftp
)
:loop
echo Checking if exit
if exist exit.pp (
echo Exiting Bye!
del exit.pp
timeout /t 2 > nul
goto EOF
)
echo Checking file...
timeout /t 1 > nul
"%curlpath%" --user %username%:%password% --head --silent %sftpmode%://%server%/%filename_save% -k > header.txt
echo "%curlpath%" --user %username%:%password% --head --silent %sftpmode%://%server%/%filename_save% -k m header.txt
for /F "tokens=2 delims=: " %%i in ('type header.txt ^| findstr /i "Content-Length:"') do set server_file_size=%%i
if exist %filename_save% (
for %%A in (%filename_save%) do set local_file_size=%%~zA
) else (
echo The message file does not exist.
set local_file_size=0
)
echo File size on the server: %server_file_size%
echo File size on the local machine: %local_file_size%
if %local_file_size% equ %server_file_size% (
echo File is the same, no changes made.
) else (
echo File has changed. Downloading file...
"%curlpath%" --user %username%:%password% -o %filename_save% %sftpmode%://%server%/%filename_save% -k
echo "%curlpath%" --user %username%:%password% -o %filename_save% %sftpmode%://%server%/%filename_save% -k
echo refreshing text screen
echo 0>text.refresh
echo sending notification
if NOT EXIST nntfdp (
if EXIST notif (
powershell -Command "[reflection.assembly]::loadwithpartialname('System.Windows.Forms'); [reflection.assembly]::loadwithpartialname('System.Drawing'); $notify = new-object system.windows.forms.notifyicon; $notify.icon = [System.Drawing.SystemIcons]::Information; $notify.visible = $true; $notify.showballoontip(10,'New Message!','You have received New Message from %user%!',[system.windows.forms.tooltipicon]::None)"
goto loop
)
) else (
del nntfdp
goto loop
)
)
goto loop
:loop2
if NOT EXIST sftpchecker (
mkdir sftpchecker
goto sftpchecked
) else (
goto sftpchecked
)
:sftpchecked
echo Checking if exit
if exist exit.pp (
echo Exiting Bye!
del exit.pp
timeout /t 2 > nul
goto EOF
)
if exist %filename_save% (
for %%A in (%filename_save%) do set local_file_size=%%~zA
) else (
echo The message file does not exist.
set local_file_size=0
)
cd sftpchecker
"%curlpath%" --user %username%:%password% -o %filename_save% %sftpmode%://%server%/%filename_save% -k
if exist %filename_save% (
for %%A in (%filename_save%) do set server_file_size=%%~zA
cd ..
) else (
echo The message file does not exist.
set server_file_size=0
)
echo File size on the server: %server_file_size%
echo File size on the local machine: %local_file_size%
if %local_file_size% equ %server_file_size% (
echo File is the same, no changes made.
) else (
echo File has changed. Downloading file...
"%curlpath%" --user %username%:%password% -o %filename_save% %sftpmode%://%server%/%filename_save% -k
echo "%curlpath%" --user %username%:%password% -o %filename_save% %sftpmode%://%server%/%filename_save% -k
echo refreshing text screen
echo 0>text.refresh
echo sending notification
if NOT EXIST nntfdp (
if EXIST notif (
powershell -Command "[reflection.assembly]::loadwithpartialname('System.Windows.Forms'); [reflection.assembly]::loadwithpartialname('System.Drawing'); $notify = new-object system.windows.forms.notifyicon; $notify.icon = [System.Drawing.SystemIcons]::Information; $notify.visible = $true; $notify.showballoontip(10,'New Message!','You have received New Message from %user%!',[system.windows.forms.tooltipicon]::None)"
goto sftpchecked
)
) else (
del nntfdp
goto sftpchecked
)
)
goto sftpchecked
:EOF
exit