天天看點

用ftp實作大檔案上傳

用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  

上傳檔案:  

‘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 "*.*"  

下載下傳檔案:  

‘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,可能程式設計實作遠端檔案定時或不定時同步等諸多功能,進而實作非手工方式的檔案傳輸。 

本文轉自today4king部落格園部落格,原文連結:http://www.cnblogs.com/jinzhao/archive/2007/07/10/813113.html,如需轉載請自行聯系原作者

繼續閱讀