您的位置:程序门 -> web 开发 -> asp



asp中如何实现ftp上传到远程服务器上?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


asp中如何实现ftp上传到远程服务器上?
发表于:2008-01-22 19:58:06 楼主
asp中如何实现ftp上传?
我有一个10g的美国空间   速度还可以
但我想将它做个附件下载空间
我在国内有个空间上如何实现用asp来   ftp上传到远程服务器上
很多php的论坛带这种远程ftp附件功能   比如phpwind
我想问下asp能实现吗
发表于:2008-01-22 21:08:361楼 得分:0
<%@   language=vbscript   %>
<%
'   ftp   via   asp   without   using   3rd-party   components
'   ben   meghreblian   15th   jan   2002
'   benmeg   at   benmeg   dot   com   /   http://benmeg.com/code/asp/ftp.asp.html
'
'   this   script   assumes   the   file   to   be   ftp'ed   is   in   the   same   directory   as   this   script.
'   it   should   be   obvious   how   to   change   this   (*hint*   change   the   lcd   line).
'   you   may   specify   a   wildcard   in   ftp_files_to_put   (e.g.   *.txt).

'   nb:   you   need   to   have   c:\winnt\system32\wshom.ocx   registered   to   use   the   wscript.shell   object.
'   it   is   registered   by   default,   but   is   sometimes   removed   for   security   reasons   (no   kidding!).
'   you   will   also   need   cmd.exe   in   the   path,   which   again   is   there,   unless   the   box   is   locked   down.
'   check   with   your   web   host/resident   sysadmin   if   in   doubt.
'
'   nb:   this   script   was   originally   written   in   response   to   a   thread   on   a   wrox   asp   mailing   list.
'   at   the   time,   i   was   hosting   on   a   shared   nt4/iis4   box   and   the   script   worked   fine.   since   i   wrote
'   it,   several   people   have   got   in   contact   asking   why   it   doesn't   work   on   later   versions   of   either
'   windows   or   iis.   the   answer   is   probably   either   as   mentioned   in   the   above   nb,   or   to   do   with
'   firewalls   restricting   outbound   traffic   from   and/or   to   certain   ports.   this   said,   many   people
'   have   successfully   used   this   code   to   ftp   to/from   windows   2000/windows   xp   boxes   running   iis5/iis6.

dim   objfso,   objtextfile,   oscript,   oscriptnet,   ofilesys,   ofile,   strcmd,   strtempfile,   strcommandresult
dim   ftp_address,   ftp_username,   ftp_password,   ftp_physical_path,   ftp_files_to_put

'   edit   these   variables   to   match   your   specifications
ftp_address                     =   "ftp.server.com"
ftp_username                   =   "username"
ftp_password                   =   "password"
ftp_remote_directory   =   "subdirectory"   '   leave   blank   if   uploading   to   root   directory
ftp_files_to_put           =   "file.txt"           '   you   can   use   wildcards   here   (e.g.   *.txt)

on   error   resume   next

set   oscript   =   server.createobject("wscript.shell")
set   ofilesys   =   server.createobject("scripting.filesystemobject")
set   objfso   =   createobject("scripting.filesystemobject")

'   build   our   ftp-commands   file
set   objtextfile   =   objfso.createtextfile(server.mappath("test.ftp"))

objtextfile.writeline   "lcd   "   &   server.mappath(".")
objtextfile.writeline   "open   "   &   ftp_address
objtextfile.writeline   ftp_username
objtextfile.writeline   ftp_password

'   check   to   see   if   we   need   to   issue   a   'cd'   command
if   ftp_remote_directory   <>   ""   then
      objtextfile.writeline   "cd   "   &   ftp_remote_directory
end   if

objtextfile.writeline   "prompt"

'   if   the   file(s)   is/are   binary   (i.e.   .jpg,   .mdb,   etc..),   uncomment   the   following   line
'   objtextfile.writeline   "binary"

'   if   there   are   multiple   files   to   put,   we   need   to   use   the   command   'mput',   instead   of   'put'
if   instr(1,   ftp_files_to_put,   "*",1)   then
      objtextfile.writeline   "mput   "   &   ftp_files_to_put
else
      objtextfile.writeline   "put   "   &   ftp_files_to_put
end   if

objtextfile.writeline   "bye"

objtextfile.close
set   objtextfile   =   nothing

'   use   cmd.exe   to   run   ftp.exe,   parsing   our   newly   created   command   file
strcmd   =   "ftp.exe   -s:"   &   server.mappath("test.ftp")
strtempfile   =   "c:\"   &   ofilesys.gettempname(   )

'   pipe   output   from   cmd.exe   to   a   temporary   file   (not   : ¦   steve)
call   oscript.run   ("cmd.exe   /c   "   &   strcmd   &   "   >   "   &   strtempfile,   0,   true)
set   ofile   =   ofilesys.opentextfile   (strtempfile,   1,   false,   0)

on   error   resume   next
'   grab   output   from   temporary   file
strcommandresult   =   server.htmlencode(   ofile.readall   )
ofile.close

'   delete   the   temporary   &   ftp-command   files
call   ofilesys.deletefile(   strtempfile,   true   )
call   objfso.deletefile(   server.mappath("test.ftp"),   true   )
set   ofilesys   =   nothing
set   objfso   =   nothing

'   print   result   of   ftp   session   to   screen
response.write(   replace(   strcommandresult,   vbcrlf,   " <br> ",   1,   -1,   1)   )
%>
发表于:2008-01-23 13:31:362楼 得分:0
  汗。。。。。。。。。。


快速检索

最新资讯
热门点击