我有这个VBScript根据文件名将特定文件发送到FTP。
Option Explicit
Dim objFSO, objMyFile, objShell, strFTPScriptFileName, strFilePut
Dim strLocalFolderName, strScriptFolder, strFTPServerName, strLoginID, strReportPath
Dim strPassword, strFTPServerFolder
Dim objArg, strIniFilePath, oShell
Dim i: i = 0
'Locates the INI File
Set objArg = WScript.Arguments
strIniFilePath = objArg(0)
'Gets FTP UserId and Password
strLocalFolderName = ReadIni(strIniFilePath,"FTP","LocalFolderName")
strFTPServerName = ReadIni(strIniFilePath,"FTP","FTPServerName")
strLoginID = ReadIni(strIniFilePath,"FTP","LoginID")
strPassword = ReadIni(strIniFilePath,"FTP","Password")
strFTPScriptFileName = ReadIni(strIniFilePath,"FTP","FTPScriptFileName")
strReportPath= Array("/davaoccc" , "/calambaccc" , "/cebuccc")
strFilePut= Array("0970*.txt" , "0979*.txt" , "0983*.txt")
Set oShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If (objFSO.FileExists(strFTPScriptFileName)) Then
objFSO.DeleteFile (strFTPScriptFileName)
End If
For i = 0 To UBound(strReportPath)
Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)
objMyFile.WriteLine ("open " & strFTPServerName)
objMyFile.WriteLine (strLoginID)
objMyFile.WriteLine (strPassword)
objMyFile.WriteLine ("cd " & strReportPath(i))
objMyFile.WriteLine ("bin")
objMyFile.WriteLine ("lcd " & strLocalFolderName)
objMyFile.WriteLine ("prompt off")
objMyFile.WriteLine ("mput " & strFilePut(i))
objMyFile.WriteLine ("disconnect")
objMyFile.WriteLine ("bye")
objMyFile.Close
'Execute the FTP script.
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run "ftp -s:" & Chr(34) & strFTPScriptFileName & Chr(34), , True
next
这是.ini文件
[FTP]
LocalFolderName=D:\Output\
FTPServerName=172.22.11.220
LoginID=user
Password=1234
FTPScriptFileName=D:\FTP_Log.txt
如您所见,变量的值位于.ini文件中(硬编码值应位于.ini文件中),但两个变量除外: strReportPath , strFilePut
FTP中有多个目标文件夹,基于文件名的不同文件(文件以0970,9979,0983开头),此VBScripts成功发送。但是我很难在如何将一个2数组变量放入config ini文件中,使得数组变量仍处于匹配状态。 (例如/ davaoccc为0970,/ calambaccc为0979,/ cebuccc为0983)
任何人都知道或有想法这样做吗?
我试图在互联网上搜索这个,但没有这个主题。非常感谢答案。
答案 0 :(得分:-2)
将数组元素放在以逗号分隔的列表中,然后编写一些VBscript来解析这些值。
strReportPath = /davaoccc,/calambaccc,/cebuccc
strFilePut= 0970*.txt,0979*.txt,0983*.txt
我假设所有值都被读作文本,因此您可以删除字符串引号。