日期:2014-04-19  浏览次数:20387 次

    用asp.net上传文件时,对大文件的处理总会不尽于人意,虽然从理论上讲,可以传输很大的文件(100M以上),但在实际使用中会出现各种问题.因此,基于B/S架构的大文件上传还是用FTP为好。

 用FTP手工上传文件没有什么可以说的,但我们往往需要通过程序来控制这一过程,即通过asp.net来实现这一目的.如果FTP软件具备可二次开发的接口就好了.经典的cuteftp pro就具有这样的功能。

 安装完cuteftp pro 7后,会生成一个文件叫ftpte(FTP传输引擎),ftpte提供了很多属性和方法,能够方便地通过编程来实现大文件的上传,包括文件过滤、目录和文件检测、文件删除、改名、传输启动和停止以及状态查看等等。

 下面是实例:

 连接FTP服务器:

Set MySite = CreateObject("CuteFTPPro.TEConnection")

MySite.Protocol = "FTP"

MySite.Host = "ftp.cuteftp.net"

MySite.Login = "username"

MySite.Password = "password"

MySite.Connect

 上传文件:

Set MySite = CreateObject("CuteFTPPro.TEConnection")

‘Specify user, pass, host, and connect as normal...

MySite.Connect ‘Recommended: call connect first

MySite.RemoteFolder = "Temp"

MySite.LocalFolder = "C:\123"

‘using relative path, all files in folder 123 are uploaded to the folder Temp off the current folder on the server.

MySite.Upload "*.*"

 下载文件:

Set MySite = CreateObject("CuteFTPPro.TEConnection")

‘Specify user, pass, host, and connect as normal...

MySite.Connect ‘Recommended: call connect first

‘next line changes to a predetermined folder so you can use a relative path in the download method

MySite.RemoteFolder = "/c:/Inetpub/ftproot/Temp/Temp/"

MsgBox (MySite.RemoteFolder) 'display current remote folder

MySite.Download "agent.ini", "c:\temp\agent1.ini"

'now verify downloaded ok

If CBool(MySite.LocalExists ("c:\temp\agent1.ini")) Then

MsgBox "File downloaded OK."

End If

 从实验的情况看,ftpte在C/S模式下能很好的支持各项功能,在B/S模式下会找不到组件,可能与没有注册有关。

 通过利用ftpte,可能编程实现远程文件定时或不定时同步等诸多功能,从而实现非手工方式的文件传输。