用ftp實現大檔案上傳

來源:互聯網
上載者:User
用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,可能編程實現遠程檔案定時或不定時同步等諸多功能,從而實現非手工方式的檔案傳輸。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.