Chinaunix首页 | 论坛 | 博客
  • 博客访问: 469910
  • 博文数量: 95
  • 博客积分: 2117
  • 博客等级: 大尉
  • 技术积分: 2301
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-16 21:10
个人简介

辽宁铁岭人,现居大连。1970年生。 先后供职于 中国国际海运网、大连学堂科技、大连华仁视线网络科技有限公司、大连中科海云科技有限公司,任职技术总监。 精通PHP、JAVA、Javascript、HTML、CSS等网络编程技术及Linux操作系统。 精通面向对象编程、设计模式、重构及互联网产品设计。

文章分类

全部博文(95)

文章存档

2013年(31)

2012年(2)

2011年(34)

2010年(25)

2008年(3)

分类: WINDOWS

2010-12-18 21:36:28

团队利用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记录,上传了哪些文件不能复查。
阅读(1979) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~