手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆

为windows的WEB服务器添加高性能的FTP组件

首页 > PHP >

在windows服务器里面,如果我们要用FTP函数,速度应该是很慢的,而且效率不高,如果有大量文件需要上传,用自带的FTP函数,恐怕是要死人的吧。
windows服务器,windows哦,可以装N多软件的windows哦。虽然不建议在服务器上装上很多软件,但是也可以装一些FTP软件的嘛。这里以cuteftp举例。
cuteftp安装完毕后,会在软件目录里有一个Scripts目录,现在的版本不象很久以前的了,如今的版里只有一个Sample.vbs,记得几年前的cuteftp里面会有各种各样的vbs文件的。
闲话不多说,打开vbs文件,内容为:

ASP/Visual Basic代码
  1. 'This default template script is in VBScript. You can write scripts in your language of choice and save them with the proper extension, or use your an editor specific to that language.  
  2. 'See the TESDK help file for more details on how the scripting feature works and for information on each supported method and property.  
  3. 'You must have Windows Scripting Host installed for the COM enabled engine to work. Run the Transfer Engine once to register it (as a COM object) on the target system.  
  4. 'If you're having problems with running scripts while not logged in, or when trying to run them using MS scheduler, refer to our online knowledgebase for help (http://www.globalscape.com/support)  
  5. 'Look into c:\temp folder to observe local activity (for testing purposes) or right click on the Transfer Engine icon in the systray and select "show current transfers"  
  6. 'This sample script performs an anonymous login to ftp://ftp.globalscape.net  
  7.    'First declare a variable called Mysite. This will hold the reference to the TE COM object.  
  8.    Dim MySite  
  9.    'Create a connection object and assign it to the variable  
  10.    Set MySite = CreateObject("CuteFTPPro.TEConnection")  
  11.    ' Now set each property for the site connection   
  12.    ' You can omit this section to use the default values, but you should at least specify the Host  
  13.    'The default Protocol is FTP, however SFTP (SSH2), FTPS (SSL), HTTP, and HTTPS can also be used)  
  14.    MySite.Protocol = "FTP"  
  15.    MySite.Host = "ftp.globalscape.com"  
  16.    'following lines are optional since the default is anonymous if no login and password are defined  
  17.    MySite.Login = "anonymous"  
  18.    MySite.Password = "user@user.com"  
  19.    'if necessary, use the UseProxy method and ProxyInfo or SocksInfo properties to connect through a proxy server  
  20.    MySite.UseProxy = "BOTH"  
  21.    'now connect to the site (also called called implicitly when most remote methods are called)  
  22.    MySite.Connect  
  23.    'perform some logic to verify that the connection was made successfully  
  24.    If (Not Cbool(MySite.IsConnected)) Then    
  25.       MsgBox "Could not connect to: " & MySite.Host & "!"  
  26.       Quit(1)  
  27.    End If  
  28.    'The script will now check to see if the local folder c:\temp exists and will create it if necessary  
  29.    If (Not (MySite.LocalExists("c:\temp"))) Then  
  30.       MySite.CreateLocalFolder "c:\temp"  
  31.    End If  
  32.    'Change TE's local working folder to to c:\temp  
  33.    MySite.LocalFolder = "c:\temp"  
  34.    'Check for existence of remote folder "/pub/cuteftp"  
  35.    b = MySite.RemoteExists("/pub/cuteftp/")  
  36.    If (Not CBool(b)) Then  
  37.       'Verify existence of remote folder  
  38.       MsgBox "Remote folder not found!. Please make sure that the Pub folder exists on the remote site"  
  39.       Quit(1)  
  40.    End If  
  41.    'Now download the index file to the local destination folder  
  42.    MySite.Download "/pub/cuteftp/index.txt"  
  43.    'Complete.  Show the status of this transfer.  
  44.    MsgBox "Task done, final status is '" + MySite.Status + "'"  
  45.   MySite.Disconnect  
  46.   MySite.Close  
  47. '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  

看到这样的文件,你应该知道如何调用一些FTP软件自带的方法了吧?

由于windows版本下的PHP直接就支持COM,所以现在我们可以直接用PHP模拟一遍:

PHP代码
  1. <?php  
  2.   
  3. $ftp  = new COM("CuteFTPPro.TEConnection");  
  4.   
  5. $ftp->Protocol = "FTP";  
  6. $ftp->Host  = "ftp.globalscape.com";  
  7.   
  8. $ftp->Login = "anonymous";  
  9. $ftp->Password = "user@user.com";  
  10.   
  11. $ftp->UseProxy = "BOTH";  
  12. $ftp->Connect();  
  13.   
  14. if ( !$ftp->IsConnected ){  
  15.     die("Could not connect to : {$ftp->Host}");  
  16. }  
  17.   
  18. if ( !$ftp->LocalExists('c:\\temp') ){  
  19.     $ftp->CreateLocalFolder('c:\\temp');  
  20. }  
  21.   
  22. $ftp->LocalFolder = 'c:\\temp';  
  23.   
  24. $remote = $ftp->RemoteExists('/pub/cuteftp/');  
  25. if ( !$remote ){  
  26.     die('Remote folder not found!. Please make sure that the Pub folder exists on the remote site');  
  27. }  
  28.   
  29. $ftp->Download('/pub/cuteftp/index.txt');  
  30. echo'Over,ftp Status:' . $ftp->Status );  
  31. $ftp->Disconnect();  
  32. $ftp->Close();  
  33.   
  34.   
  35. ?>  

执行一下,OK,显示:Over,ftp Status:FINISHED,同时c盘根目录下有一个temp目录,里面下载了那个:index.txt文件。测试完毕。。(PS:对于这样的转换实在没有技术含量啊。呵呵,直接把“.”换成“->”就完事了。)
更多的函数,请参考cuteftp帮助文件:

大小: 369.36 K
尺寸: 400 x 264
浏览: 1465 次
点击打开新窗口浏览全图



本站采用创作共享版权协议, 要求署名、非商业和保持一致. 本站欢迎任何非商业应用的转载, 但须注明出自"易栈网-膘叔", 保留原始链接, 此外还必须标注原文标题和链接.

Tags: ftp, com, windows, cuteftp, vbs

« 上一篇 | 下一篇 »

只显示10条记录相关文章

感谢老王的:Object-C之Windows版Hello, World! (浏览: 42188, 评论: 3)
闲着无聊,用WPS生成文档 (浏览: 29910, 评论: 1)
wubi惊魂 (浏览: 25599, 评论: 2)
惊心动魄的几小时 (浏览: 24494, 评论: 3)
Windows下SVN服务器的架设 (浏览: 23901, 评论: 0)
Ubuntu创始人:Linux的未来并不在于对Windows的兼容性 (浏览: 20432, 评论: 1)
Windows Server 2008登陆Dreamspark 免费使用 (浏览: 19612, 评论: 0)
盗版WINDOWS要被大动作处理了 (浏览: 19384, 评论: 1)
【科普贴】话说回车和换行 (浏览: 19080, 评论: 0)
ZZ:IIS7在Windows Server 2008 R2中的新改进 (浏览: 18957, 评论: 0)

发表评论

评论内容 (必填):