yunshan 2007-2-7 20:48
在提交记录的同时,把它的附件上传到一个FTP上
对于比大的项目来说,CQ不仅管理了所有的defect信息,可能也管理了很多其他信息,如需求等。
而所有的这些信息中,有很多信息都包含有附件,如defect中会有screenshot(defect的抓图),
而需求中又可能会有需求文档文件信息。其中的一些都是很重要的,所以需要动态的把这些文件
保存的一个别的位置,如一个FTP上(保存到本地某个目录相对比较简单,在此不作介绍)。
以下就是对这个问题的一个解决方案。
问题描述:在Submit一个defect时,把这个defect的附件全部上传到一个FTP服务器上。
--------------------------------------------------------------------------------------------------------------------
问题分解:首先通过CQ的API取得当前record的所有attachment,然后把它们保存到本地的一个临
时目录中(在此为C:\temp),其次就是把这些文件上传到目标FTP上(需要一个有写权限的
FTP帐号),最后,删除本地临时目录中的临时文件。
--------------------------------------------------------------------------------------------------------------------
问题解决:在这个解决方案中,因为涉及到对FTP的操作,所以引入了一个比较有用的组件ChilkatFtp,
这个组件需要下载安装,使用起来简单,方便,是目前比较好的一个FTP组件,提供免费下载,
地址为:[url=http://www.chilkatsoft.com/downloads.asp]http://www.chilkatsoft.com/downloads.asp[/url],然后下载Chilkat's (Free) FTP ActiveX,
下载后直接安装, 然后就可以使用。
提示:当提交bug时,script首先会在CQAttach目录下以这个defect的ID为名,create一个文件夹,
如pro000001,然后把这个object的附件上传到这个下面。
--------------------------------------------------------------------------------------------------------------------
'---------------------------------------------------------------------------------------------------------------'
' Script Name: Upload_File_To_FTP_AT_Submitting.vbs '
' Author: yunshan '
' Date: 2007-2-7 '
' Description: [b]Add this script to the commit hook of the Submit in ClearQuest[/b], if there '
' have attachments with the current object, these attachment will be upload the FTP '
' server when submit it. You just need change the config info to meet your need. '
' Enjoy it and Happy new year! '
'---------------------------------------------------------------------------------------------------------------'
Const OTEMP = "C:\temp\" ' This is the local cache folder
Const OREMOTE = "CQAttach\" ' This is the destination folder on the FTP under the root
Const USERNAME = "loginname" ' This is the user name for login to the server
Const PASSWORD = "password" ' This is the password
Const HOSTNAME = "127.0.0.1" ' This is the FTP Address
Dim session
Dim fso
Dim ftp
Dim oID
Dim oFileName
Set session = GetSession
Set fso = CreateObject("Scripting.FileSystemObject")
Set ftp = CreateObject("ChilkatFTP.ChilkatFTP")
' if the cache folder not exist, then create it
If Not fso.FolderExists(OTEMP) Then
fso.CreateFolder(OTEMP)
End If
' Connect to the FTP server
[url=ftp://ftp.Username]ftp.Username[/url] = USERNAME
[url=ftp://ftp.Password]ftp.Password[/url] = PASSWORD
[url=ftp://ftp.Hostname]ftp.Hostname[/url] = HOSTNAME
OK = [url=ftp://ftp.Connect]ftp.Connect[/url]
If OK <> 1 Then
WScript.Echo [url=ftp://ftp.LastErrorText]ftp.LastErrorText[/url]
End If
' Switch to the destination folder on the remote FTP server
[url=ftp://ftp.ChangeRemoteDir]ftp.ChangeRemoteDir[/url] OREMOTE
oID = GetfieldValue("id").GetValue
[url=ftp://ftp.CreateRemoteDir]ftp.CreateRemoteDir[/url] oID
[url=ftp://ftp.ChangeRemoteDir]ftp.ChangeRemoteDir[/url] oID
' get all the attachments of the current entity
' and put them on the FTP when submit the defect
Set oAttachFields = AttachmentFields
Set oAttachField = oAttachFields.Item(0)
Set oAttachments = oAttachField.Attachments
For Each oAttachment In oAttachments
oFileName = OTEMP & fso.GetFileName(oAttachment.FileName)
' oAttachment.Load oFileName
fso.CopyFile oAttachment.FileName, OTEMP
OK = [url=ftp://ftp.PutFile(oFileName]ftp.PutFile(oFileName[/url], fso.GetFileName(oAttachment.FileName))
If OK <> 1 Then
WScript.Echo [url=ftp://ftp.LastErrorText]ftp.LastErrorText[/url]
End If
Next
' Shutdown the connection
[url=ftp://ftp.Disconnect]ftp.Disconnect[/url]
' Clear all the contents in the local temp folder
fso.DeleteFile OTEMP & "*.*"
' Release all the objects
Set oAttachments = Nothing
Set oAttachField = Nothing
Set oAttachFields = Nothing
Set ftp = Nothing
Set fso = Nothing
Set session = Nothing
------------------------------------------------------------------------------------------------------------------------------
以下为这个FTP组件的属性和method的说明
------------------------------------------------------------------------------------------------------------------------------
[font=Verdana][size=+2][color=#333333][i][b]Properties[/b][/i][/color][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]Hostname As String[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]The FTP server hostname.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]IsConnected As Long (read-only)[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Returns true if currently connected and logged into an FTP server, otherwise returns false.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]LastErrorHtml As String (read-only)[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Error information in HTML format for the last method called.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]LastErrorText As String (read-only)[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Error information in plain-text format for the last method called.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]LastErrorXml As String (read-only)[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Error information in XML format for the last method called.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]ListPattern As String[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]A wildcard pattern, defaulting to "*" that determines the files and directories included in the following properties and methods: NumFilesAndDirs, GetCreateTime, GetFilename, GetIsDirectory, GetLastAccessTime, GetModifiedTime, GetSize.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]NumFilesAndDirs As Long (read-only)[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]The number of files and sub-directories in the current remote directory that match the ListPattern. (The ListPattern defaults to "*", so unless changed, this is the total number of files and sub-directories.)[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]Passive As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Set to true for FTP to operate in passive mode, otherwise set to false for non-passive (the default).[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]Password As String[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Password for logging into the FTP server.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]Port As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Port number. Automatically defaults to the default port for the FTP service.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]Proxy As String[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]The name of a proxy server when accessing FTP via a proxy .[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]UseIEProxy As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Set this property to true to use the FTP proxy configured for Internet Explorer.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]Username As String[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Username for logging into the FTP server. Defaults to "anonymous".[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]Version As String (read-only)[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Version of the component, such as "1.0.0"[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[i][font=Verdana][size=+2][color=#333333][b]Methods[/b][/color][/size][/font][/i]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]ChangeRemoteDir(relativeDirPath As String) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Changes the current remote directory.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]Connect() As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Connects and logs in to the FTP server using the username/password provided in the component properties.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]CreateRemoteDir(dir As String) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Creates a directory on the FTP server. Returns true for success, false for failure. If the directory already exists, a new one is not created and false is returned.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]DeleteMatching(remotePattern As String) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Deletes all the files in the current remote FTP directory matching the pattern. Returns the number of files deleted, or -1 for failure. The pattern is a string such as "*.txt", where any number of "*" or "?" wildcard characters can be used. "*" matches 0 or more of any character, and "?" matches exactly 1 of any character.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]DeleteRemoteFile(filename As String) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Deletes a file on the FTP server.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]Disconnect()[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Disconnects from the FTP server, ending the current session.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]GetCreateTime(index As Long) As Date[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Returns the create time for the Nth file or sub-directory in the current remote directory. The first file/dir is at index 0, and the last one is at index (NumFilesAndDirs-1)[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]GetCurrentDirListing(pattern As String) As String[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Returns (in XML format) the files and directories in the current directory matching the pattern. Passing "*.*" will return all the files and directories.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]GetCurrentRemoteDir() As String[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Returns the current remote directory.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]GetFile(remoteFilename As String, localFilename As String) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Copies a file from the FTP server to the local filesystem. Returns true for success and false for failure.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]GetFilename(index As Long) As String[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Returns the filename for the Nth file or sub-directory in the current remote directory. The first file/dir is at index 0, and the last one is at index (NumFilesAndDirs-1)[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]GetIsDirectory(index As Long) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Returns1 for a sub-directory and 0 for a file, for the Nth entry in the current remote directory. The first file/dir is at index 0, and the last one is at index (NumFilesAndDirs-1)[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]GetLastAccessTime(index As Long) As Date[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Returns the last access time for the Nth file or sub-directory in the current remote directory. The first file/dir is at index 0, and the last one is at index (NumFilesAndDirs-1)[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]GetLastModifiedTime(index As Long) As Date[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Returns the last modified time for the Nth file or sub-directory in the current remote directory. The first file/dir is at index 0, and the last one is at index (NumFilesAndDirs-1)[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]GetRemoteFileBinaryData(remoteFilename As String) As Variant[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Returns the contents of a remote file. A null is returned on failure.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]GetRemoteFileTextData(remoteFilename As String) As String[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Returns the contents of a remote file. A null is returned on failure.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]GetSize(index As Long) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Returns the size of the Nth remote file in the current directory.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]MGetFiles(remotePattern As String, localDir As String) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Copies all the files in the current remote FTP directory to a local directory. To copy all the files in a remote directory, set remotePattern to "*.*" The pattern can contain any number of "*" or "?" characters where "*" matches 0 or more of any character, and "?" matches any single character. The return value is the number of files transferred, and on error, a value of -1 is returned. Detailed information about the transfer can be obtained from the XML log.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]MPutFiles(pattern As String) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Copies all the files matching pattern on the local computer to the current remote FTP directory. The pattern parameter can include directory information, such as "C:/my_dir/*.txt" or it can simply be a pattern such as "*.*" that matches the files in the application's current directory. Subdirectories are not recursed. The return value is the number of files copied, with a value of -1 returned for errors. Detailed information about the transfer can be obtained from the XML log.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]PutFile(localFilename As String, remoteFilename As String) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Copies a local file to the current directory on the FTP server.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]PutFileFromBinaryData(remoteFilename As String, binaryData As Variant) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Creates a file on the remote server containing the data passed in a byte array. Returns true for success, false for failure.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]PutFileFromTextData(remoteFilename As String, textData As String) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Creates a file on the remote server containing the data passed in a string. Returns true for success, false for failure.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]RemoveRemoteDir(dir As String) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Removes a directory from the FTP server.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]RenameRemoteFile(existingFilename As String, newFilename As String) As Long[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Renames a file on the FTP server.[/size][/font]
[font=MS Sans Serif][size=2][/size][/font]
[url=http://www.chilkatsoft.com/RefQuestion.asp?methodName=][font=Courier New][size=2][color=#333333][b]SaveLastError(filename As String)[/b][/color][/size][/font][/url]
[font=MS Sans Serif][size=2]Saves the last error information to an XML formatted file.[/size][/font]
killer215 2007-2-7 22:06
回复 #1 yunshan 的帖子
yunshan好贴。不过我不明白把附件上传的FTP的作用是什么?由于附件非常占用数据库的空间,要经常移动,所以我想实现一个附件能够保存到FTP 服务器上,而不是保存到数据库,而且每次读取纪录时也能从FTP服务器上读取到这个附件,也就是对用户来说没有区别,但附件不在保存到数据库了。你的帖子给了我一个思路,这段时间正在研究这个实现,在IBM网站上看到一个处理方法到还没有仔细研究,而且是perl写的,看这几天有没有时间研究下这个问题。如果yunshan和坛子了其他高手有什么好的想法也麻烦大家分享一下。
听雨屋檐人 2007-2-8 08:55
yunshan太强悍!这个正好需要!
谁比我还快?加了精华?
tianting004 2007-2-8 08:58
真遗憾,一点都看不懂啊,能不能给点简单易懂的啊
yunshan 2007-2-8 08:59
回复 #2 killer215 的帖子
这个上传到FTP上,其实就是相当于一个备份,而CQ每次读取仍然是本地的数据。
ljs53 2007-2-9 15:14
回复 #5 yunshan 的帖子
yunshan
实践了以后
感觉很实用
但是如果有多个附件的字段
它只会上传第一个附件 后面的不上传
还有有没有方法只上传指定字段的附件呀??
yunshan 2007-2-12 09:03
回复 #6 ljs53 的帖子
如果有多个attachment字段,其实也很简单,只要把其中的for循环改一下就可以了,
Set oAttachFields = AttachmentFields
for each oAttachField in oAttachFields
Set oAttachments = oAttachField.Attachments
For Each oAttachment In oAttachments
do something....
Next
Next
听雨屋檐人 2007-2-12 09:08
Set oAttachField = oAttachFields.Item(0)
我是更改了这里!来取其他附件!呵呵!
一用循环我的服务器就被干坏了!不知道为啥!寒
yunshan 2007-2-12 09:37
' 先在本地调试一下,这个问题应该不大
' Show the number of attachment fields
' 我想不至于死循环的
oAttachNum = oAttachFields.Count
MsgBox "Number of attachment fields: " & oAttachNum
ljs53 2007-2-12 09:40
回复 #7 yunshan 的帖子
这段代码有问题
会报错
听雨屋檐人 2007-2-12 09:51
[quote]原帖由 [i]ljs53[/i] 于 2007-2-12 09:40 发表
这段代码有问题
会报错 [/quote]
把报错发上来看看!
ljs53 2007-2-12 09:57
[quote]原帖由 [i]yunshan[/i] 于 2007-2-11 17:03 发表
如果有多个attachment字段,其实也很简单,只要把其中的for循环改一下就可以了,
Set oAttachFields = AttachmentFields
for each oAttachField in oAttachFields
Set oAttachments = oAttachField.Atta ... [/quote]
我用的这段代码
插入了以后
报错
yunshan 2007-2-12 12:10
回复 #12 ljs53 的帖子
我刚才在这一句
Set oAttachFields = AttachmentFields
后加入了这一行code,
MsgBox oAttachFields.Count
成功的执行了,没有发现任何问题,
看看是否是其他问题。
ljs53 2007-2-13 09:29
yunshan
我后来想实现这样一个功能
我表里面还有一个字段是Int_Branch_Name
我想根据这个字段的值
去改变ftp的目录
我是这样写的代码
Const OTEMP = "C:\temp\" ' This is the local cache folder
Const OREMOTE = "for ljs" ' This is the destination folder on the FTP under the root
Const USERNAME = "submit" ' This is the user name for login to the server
Const PASSWORD = "msh" ' This is the password
Const HOSTNAME = "192.168.1.202" ' This is the FTP Address
Dim session
Dim fso
Dim ftp
Dim oID
Dim oFileName
Dim File
Dim Ftpfile
Set session = GetSession
Set fso = CreateObject("Scripting.FileSystemObject")
Set ftp = CreateObject("ChilkatFTP.ChilkatFTP")
' if the cache folder not exist, then create it
If Not fso.FolderExists(OTEMP) Then
fso.CreateFolder(OTEMP)
End If
' Connect to the FTP server
[url=ftp://ftp.Username]ftp.Username[/url] = USERNAME
[url=ftp://ftp.Password]ftp.Password[/url] = PASSWORD
[url=ftp://ftp.Hostname]ftp.Hostname[/url] = HOSTNAME
OK = [url=ftp://ftp.Connect]ftp.Connect[/url]
If OK <> 1 Then
WScript.Echo [url=ftp://ftp.LastErrorText]ftp.LastErrorText[/url]
End If
' Switch to the destination folder on the remote FTP server
set File = GetfieldValue("Int_Branch_Name")
value = File.GetValue
select case value
case "int_apollo_admin"
choices.AddItem("apollo")
case "int_viola_admin"
choices.AddItem("viola")
case "int_mango_admin"
choices.AddItem("mango")
end select
set Ftpfile = "OREMOTE"+"\"+"value"
[url=ftp://ftp.ChangeRemoteDir]ftp.ChangeRemoteDir[/url] Ftpfile
oID = GetfieldValue("HeadLine").GetValue
[url=ftp://ftp.CreateRemoteDir]ftp.CreateRemoteDir[/url] oID
[url=ftp://ftp.ChangeRemoteDir]ftp.ChangeRemoteDir[/url] oID
' get all the attachments of the current entity
' and put them on the FTP when submit the defect
Set oAttachFields = AttachmentFields
Set oAttachField = oAttachFields.Item(1)
Set oAttachments = oAttachField.Attachments
For Each oAttachment In oAttachments
oFileName = OTEMP & fso.GetFileName(oAttachment.FileName)
' oAttachment.Load oFileName
fso.CopyFile oAttachment.FileName, OTEMP
OK = [url=ftp://ftp.PutFile(oFileName]ftp.PutFile(oFileName[/url], fso.GetFileName(oAttachment.FileName))
If OK <> 1 Then
WScript.Echo [url=ftp://ftp.LastErrorText]ftp.LastErrorText[/url]
End If
Next
' Shutdown the connection
[url=ftp://ftp.Disconnect]ftp.Disconnect[/url]
' Clear all the contents in the local temp folder
fso.DeleteFile OTEMP & "*.*"
' Release all the objects
Set oAttachments = Nothing
Set oAttachField = Nothing
Set oAttachFields = Nothing
Set ftp = Nothing
Set fso = Nothing
Set session = Nothing
这样写完了老是报错
有什么问题吗 ?
ljs53 2007-2-13 11:44
报这个错误
你看一下
[[i] 本帖最后由 ljs53 于 2007-2-12 19:45 编辑 [/i]]
yunshan 2007-2-13 12:20
回复 #16 ljs53 的帖子
我感觉你这句code有问题,
set Ftpfile = "OREMOTE"+"\"+"value"
改成
Ftpfile = OREMOTE + "\"+ value
试试~
yunshan 2007-2-13 14:16
value = GetfieldValue("Int_Branch_Name").GetValue
[b] select case value
case "int_apollo_admin"
choices.AddItem("apollo")
case "int_viola_admin"
choices.AddItem("viola")
case "int_mango_admin"
choices.AddItem("mango")
end select[/b]
Ftpfile = OREMOTE & "\" & value
ftp.ChangeRemoteDir Ftpfile
oID = GetfieldValue("ID").GetValue
ftp.CreateRemoteDir oID
ftp.ChangeRemoteDir oID
作如上改动,黑体部分应该去掉
iltest 2007-3-13 14:52
' Connect to the FTP server
ftp.Username = USERNAME
ftp.Password = PASSWORD
ftp.Hostname = HOSTNAME
OK = ftp.Connect
If OK <> 1 Then
WScript.Echo ftp.LastErrorText
End If
弱弱的问一下:
我编译没错,但是用测试数据库在提交bug时,提示:缺少"wscript对象",有没有谁知道原因?