团队利用SVN进行版本管理,但是将经过了本地测试的文件上传至服务器仍然需要使用FTP,需要由相关人员提供要上传的文件,使用CuteFTP上传至服务器。手工上传是件很机械的工作,耗时、枯燥、易出错,而且效率低下,占用了负责上传的人员的大量宝贵时间。
CuteFTP可以编写脚本完成自动上传,解放了上传人员,提高了效率,减少了漏传和误传的机会。
实现的步骤如下:
1. 在CuteFTP中设置FTP站点,在Action标签中设置服务器上站点的根文件夹和相应的本地根文件夹。
2. 连接服务器,选择
tools>Macros &
Scripting>New,生成Sample.vbs文件,修改其中的部分内容,最终的内容如下:
Dim objArgs, MySite, theFile,
Fso, Line
Set
objArgs
=
WScript.Arguments
'Create a connection object
and assign it to the variable
Set MySite =
CreateObject("CuteFTPPro.TEConnection")
' Now set each property for
the site connection
' You can omit this section to
use the default values, but you should at least specify the
Host
'The default Protocol is FTP,
however SFTP (SSH2), FTPS (SSL), HTTP, and HTTPS can also be
used)
MySite.Protocol = "FTP"
MySite.Host =
"ftp.globalscape.com"
'following lines are optional
since the default is anonymous if no login and password are
defined
MySite.Login =
"anonymous"
MySite.Password =
"user@user.com"
'if necessary, use the
UseProxy method and ProxyInfo or SocksInfo properties to connect
through a proxy server
MySite.UseProxy = "BOTH"
'now connect to the site (also
called called implicitly when most remote methods are called)
MySite.Connect
'perform some logic to verify
that the connection was made successfully
If (Not
Cbool(MySite.IsConnected))
Then
MsgBox "Could not connect to: " & MySite.Host
& "!"
Quit(1)
End If
'upload special files and
folders in provied files.
For I = 0 To objArgs.Count -
1
If (Not (MySite.LocalExists("E:\\renji\\" &
objArgs(I)))) Then
MsgBox objArgs(I) & " not exists!"
Else
Set Fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile("E:\\renji\\"
& objArgs(I), 1, False)
Do While theFile.AtEndOfStream <>
True
Line =
theFile.ReadLine
MySite.Upload2 Line, Line, 1, teRULE_OVERWRITE
Loop
theFile.Close
End If
Next
'Complete.
Show the status of this transfer.
MsgBox "Task done, final
status is '" + MySite.Status + "'"
MySite.Disconnect
MySite.Close
'End of sample script. You can save you script and then run it by
either selecting it from the Tools > Run Script menu
or by double clicking on the script file in Windows
保存。
在红色行指定的E:\\renji(此文件夹请根据实际情况设定)中,建立文本文件(假设为one.txt),内容为要上传的文件或文件夹,每个要上传的文件或文件夹占一行,为相对于站点根文件夹的相对路径,例如:
/source/function_look.php
/oursource
/image/icon.png
/css
在命令行下执行:
sample.vbs one.txt
即可自动完成上传。如果有多个人的多组文件上传,每个人都提供了一个文本文件,可以用如下方式使用此脚本:
sample.vbs one.txt two.txt three.txt
此脚本还有待完善,因为没有错误处理,如果文本文件有问题,可能会意外终止,造成上传不全。另外,没有log记录,上传了哪些文件不能复查。
阅读(2157) | 评论(0) | 转发(0) |