您好我需要批量编写脚本,我需要先检查ftp服务器是否响应。如果没有,则需要向我发送一封电子邮件,说明服务器无法连接,如果是,那么我需要每天将一些文件从我的系统传输到ftp服务器。我有程序的第二部分,但有人可以帮助我检查服务器是否响应脚本并发送电子邮件。
我有ftp server = x,port = 22,userID = abc Pass = xyz
这将是一个很大的帮助。提前谢谢。
答案 0 :(得分:0)
这使用了您可以在google上找到的免费脚本化telnet客户端:
Telnet Scripting Tool v.1.0
by Albert Yale
此脚本检查服务器,如果它返回带回车符的任何提示,则日志文件将大于零字节,因此当日志文件为零字节时,服务器没有响应,电子邮件将被发送。
阅读代码以了解如何输入电子邮件详细信息。
@echo off
set server=ftp.mydomain.com
(
echo %server% 21
echo WAIT "\m"
echo SEND ""
)>"%temp%\tst.script"
del "%temp%\tst.info" 2>nul
tst10.exe /r:"%temp%\tst.script" /o:"%temp%\tst.info" /m
for %%a in ("%temp%\tst.info") do if %%~za EQU 0 goto :email
del "%temp%\tst.script" "%temp%\tst.info"
echo run FTP script here
goto :EOF
:email :::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
:: use these settings to send from a gmail account
:: set port=465 and set SSL=True
:: use these settings for standard email SMTP port and no encryption
:: set port=25 and set SSL=False
:: Change these following items to use the same variables all the time
:: or use the command line to pass all the variables
set Port=25
set SSL=False
set From="myemail@myemailserver.com"
set To="recipient@server.com"
set Subject="FTP warning"
set Body="FTP server %server% not online"
set SMTPServer="mailservername.myemailserver.com"
set User="username"
set Pass="password"
REM set fileattach="d:\myfolder\file.txt"
:: This section sets the command line arguments
:: use this format: CALL email.bat "myname@gmail.com" "RecipientEmailAddress@server.com" "Subject line" "Email Body in one line" "smtp.gmail.com" "myname@gmail.com" "password" "d:\folder\filename to attach.txt"
if "%~7" NEQ "" (
set From="%~1"
set To="%~2"
set Subject="%~3"
set Body="%~4"
set SMTPServer="%~5"
set User="%~6"
set Pass="%~7"
set fileattach="%~8"
)
set "vbsfile=%temp%\email-bat.vbs"
del "%vbsfile%" 2>nul
set cdoSchema=http://schemas.microsoft.com/cdo/configuration
echo >>"%vbsfile%" Set objArgs = WScript.Arguments
echo >>"%vbsfile%" Set objEmail = CreateObject("CDO.Message")
echo >>"%vbsfile%" objEmail.From = %From%
echo >>"%vbsfile%" objEmail.To = %To%
echo >>"%vbsfile%" objEmail.Subject = %Subject%
echo >>"%vbsfile%" objEmail.Textbody = %body%
if exist %fileattach% echo >>"%vbsfile%" objEmail.AddAttachment %fileattach%
echo >>"%vbsfile%" with objEmail.Configuration.Fields
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusing") = 2 ' not local, smtp
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserver") = %SMTPServer%
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = %port%
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusername") = %user%
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendpassword") = %pass%
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = %SSL%
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 30
echo >>"%vbsfile%" .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send
cscript.exe /nologo "%vbsfile%"
echo email sent (if variables were correct)
del "%vbsfile%" 2>nul
del "%temp%\tst.script" "%temp%\tst.info"
goto :EOF