vcstone
初级用户
积分 98
发帖 39
注册 2007-3-16
状态 离线
|
『楼 主』:
vbs实现自动FTP问题?
环境:xp sp2 或2K3
现状况:自己已经乱乱的写了一个,调动cmd然后再FTP的.用sendkeys实现自动输入.
(程序文件夹中有kk.mdb,cmd.bat--里面调用cmd.exe,AutoFTP.vbs)
希望实现:用vbs实现自动登陆FTP并上传文件;脚本有没有直接FTP的方法不用调用cmd,不太希望有弹出窗口,因为更新时仍进行其它操作,焦点一变sendkeys就失效了.
Quote: | dim auto
dim fso
dim name
dim date
dim last
Dim ts,i,one,two,three
one=5
two=0
three=5
name=trim(inputbox("请输入需要升级的机器IP地址的最后一位,如:236","程序运行时请勿进行其它操作,谢谢!"))
set auto=createobject("wscript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
do until fso.fileexists("kk.mdb")
msgbox "没找到kk.mdb文件,你改好名了吗?"
wscript.sleep 4000
loop
app_window=auto.run ("cmd.bat")
wscript.sleep 400
auto.AppActivate app_window
wscript.sleep 200
auto.SendKeys "ftp 192.168.1."
wscript.sleep 300
auto.SendKeys name
wscript.sleep 300
auto.SendKeys " >c:\windows\ftp.txt"
wscript.sleep 300
auto.SendKeys "{enter}"
wscript.sleep 2000
Do While Not i=1
Set ts=fso.opentextfile("c:\windows\ftp.txt")
Do While Not ts.AtEndOfStream
data=trim(ts.readline)
If instr(data,"ready") Then
auto.AppActivate app_window
auto.SendKeys "anonymous"
wscript.sleep 300
auto.SendKeys "{enter}"
wscript.sleep 300
auto.SendKeys "dd"
wscript.sleep 300
auto.SendKeys "{enter}"
wscript.sleep 500
auto.SendKeys "put kk.mdb"
auto.SendKeys "{enter}"
i=1
Exit Do
End If
one=one-1
if one=0 then
msgbox "连接失败,请检查设置和网络..程序即将退出!"
wscript.sleep 300
wscript.quit
end if
loop
Set ts = nothing
set fso = nothing
wscript.sleep 300
loop
set wshshell = CreateObject("WScript.Shell")
timeout = 3
result = wshshell.Popup("系统升级进行中....", timeout, "请稍后", vbExclamation)
wscript.sleep 15000
Do While Not i=2
Set fso = CreateObject("Scripting.FileSystemObject")
Set last=fso.opentextfile("c:\windows\ftp.txt")
Do While Not last.AtEndOfStream
data=trim(last.readline)
If instr(data,"bytes") Then
msgbox "更新完成,请重启机器!"
wscript.sleep 200
auto.AppActivate app_window
auto.SendKeys "bye"
wscript.sleep 200
auto.SendKeys "{enter}"
i=2
Exit Do
End If
wscript.sleep 3000
two=two+1
if two>=30 then
msgbox "网络连接相当缓慢,请重新运行升级程序!"
wscript.quit
end if
loop
Set last = nothing
Set fso = nothing
loop |
|
|
|