用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,可能編程實現遠程文件定時或不定時同步等諸多功能,從而實現非手工方式的文件傳輸。
新聞熱點
疑難解答