VBS上传文件(调用ftp)

首先创建一个UploadFile.bat 文件 ,

内容为 :ftp -s:ftp.cfg

dim rs,conn,sConn

Dim strDate

Dim fs,txtname,oldtxtname

Dim txtpath 

strDate = Date

' 写文件

set fs = createobject("scripting.filesystemobject")

txtpath = "D:\bak\"

txtname ="ServiceEvaluation_backup_" & Year(strDate) & Right("0" & Month(strDate),2) & Right("0" & Day(strDate),2) & ".bak"

' 上传ftp

' 删除旧ftp配置

If fs.fileExists("ftp.cfg") Then

  fs.DeleteFile("ftp.cfg")

End If

' 写新ftp配置

set f=fs.opentextfile("ftp.cfg",2, true)

f.WriteLine("open 192.168.20.124 21") 'ftp ip 

f.WriteLine("User_name")  ’ftp 服务器用户名

f.WriteLine("UserPassword")  'ftp服务器密码

f.WriteLine("cd /192.168.20.156/") 'ftp 目录

f.WriteLine("put " & txtpath & txtname & " " & txtname)

f.WriteLine("bye")

f.Close

' 开始上传

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.run WshShell.CurrentDirectory & "\UploadFile.bat", 5, True