Foros del Web » Programando para Internet » ASP Clásico »

Gestionar FTP mediante ASP

Estas en el tema de Gestionar FTP mediante ASP en el foro de ASP Clásico en Foros del Web. Buenas: Pues eso mismo, que si alguien sabe si se puede y cómo, gestionar un FTP desde ASP. PD: He intentado buscar en el foro ...
  #1 (permalink)  
Antiguo 23/05/2006, 01:29
 
Fecha de Ingreso: octubre-2004
Mensajes: 104
Antigüedad: 20 años, 6 meses
Puntos: 0
Gestionar FTP mediante ASP

Buenas:

Pues eso mismo, que si alguien sabe si se puede y cómo, gestionar un FTP desde ASP.

PD: He intentado buscar en el foro pero siempre sale la palabra FTP como demasiado frecuente y no me la incluye en la búsqueda.

Gracias y un saludo .
  #2 (permalink)  
Antiguo 23/05/2006, 02:42
 
Fecha de Ingreso: enero-2006
Ubicación: Torroles (Costa der Só)
Mensajes: 1.017
Antigüedad: 19 años, 4 meses
Puntos: 7
Busca en Google "componente FTP ASP"



Un saludo
__________________
"Tus pecados son el estiércol sobre el que florecerán las flores de tus virtudes" - Gerald Messadié -
  #3 (permalink)  
Antiguo 23/05/2006, 04:18
Avatar de trasgukabi  
Fecha de Ingreso: septiembre-2004
Mensajes: 2.749
Antigüedad: 20 años, 8 meses
Puntos: 18
he encontrado esto pero no lo he probado, Si te sirve, dilo. Un saludo.
Código:
<%@ Language=VBScript %>
<%
' FTP via ASP without using 3rd-party components
' Ben Meghreblian 15th Jan 2002
' benmeg at benmeg dot com / http://benmeg.com
'
' 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) )
%>
  #4 (permalink)  
Antiguo 23/05/2006, 05:51
 
Fecha de Ingreso: octubre-2004
Mensajes: 104
Antigüedad: 20 años, 6 meses
Puntos: 0
Trasgukabi no he probado si funciona, probablemente sí, pero esa solución no me sirve. La cuestión es que necesito que coja los ficheros del cliente, no del servidor. Ese es el mayor problema porque todo lo que encuentro es para mover archivos dentro del mismo servidor, y yo lo que necesito es igual que un upload normal y corriente pero en FTP.

Si encontráis algun componente gratuito o algun script os lo agradecería, yo en todos los que he encontrado me he topado con el "does not read client-side files".

Gracias de todas formas, un saludo
  #5 (permalink)  
Antiguo 06/11/2006, 22:35
 
Fecha de Ingreso: noviembre-2006
Mensajes: 1
Antigüedad: 18 años, 6 meses
Puntos: 0
De acuerdo Este código gestiona un archivo, pero es fácil modificarlo para varios.

<%@LANGUAGE="VBSCRIPT"%>
<%response.buffer=true
Func = Request("Func")
if isempty(Func) Then
Func = 1
End if
Select Case Func
Case 1
%>

<table width="420" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#0066CC">
<tr>
<td bgcolor="#FFFFFF" bordercolor="#FFFFFF">
<div id="sombra" style="position:relative;height:50;top:0;text-align:center;filter:shadow(color=gray)">
<font color="#0066CC" size="6">Subir archivos al servidor.</font></DIV>
</td>
</tr>
</table>
<FORM ENCTYPE="multipart/form-data" ACTION="saveany.asp?func=2" METHOD=POST id=form1 name=form1>
<TABLE align="center" width="425" border="1" bordercolor="#0066CC" cellspacing="5" cellpadding="5">
<TR>
<TD>
<p><b><font color="#FFFFFF">a</font>Instrucciones:</b></p>
<ol>
<li><font color="#330066" size="2">Pulsa en el botón examinar y elige
el archivo de tu ordenador.</font></li>
<li><font color="#330066" size="2">Luego pulsa el botón subir. </font></li>
<li><font color="#330066" size="2">Espere, recibirá la notificación
al terminar de subir el archivo.</font></li>
</ol>
</TD>
</TR>
<TR>
<TD bordercolor="#0066CC"><STRONG><font color="#330066" size="2"><b><font color="#FFFFFF">a</font></b>Nombre
del archivo a subir ...</font></STRONG> <font size="2"> <b><font color="#FFFFFF"><br>
aa
<br>
a</font></b><b><font color="#FFFFFF">a</font></b>
<INPUT NAME=File1 SIZE=30 TYPE=file>
<b><font color="#FFFFFF">a</font></b><b><font color="#FFFFFF">a</font></b><b><font color="#FFFFFF">a
</font></b> </font>
<INPUT type="submit" value="Subir">
</TD>
</TR>
</TABLE>
</FORM>
<%
Case 2
ForWriting = 2
adLongVarChar = 201
lngNumberUploaded = 0

'Get binary data from form
noBytes = Request.TotalBytes
binData = Request.BinaryRead (noBytes)
'convery the binary data to a string
Set RST = CreateObject("ADODB.Recordset")
LenBinary = LenB(binData)

if LenBinary > 0 Then
RST.Fields.Append "myBinary", adLongVarChar, LenBinary
RST.Open
RST.AddNew
RST("myBinary").AppendChunk BinData
RST.Update
strDataWhole = RST("myBinary")
End if
'Creates a raw data file for with all
' data sent. Uncomment for debuging.
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set f = fso.OpenTextFile(server.mappath(".") & "\raw.txt", ForWriting, True)
'f.Write strDataWhole
'set f = nothing
'set fso = nothing
'get the boundry indicator
strBoundry = Request.ServerVariables ("HTTP_CONTENT_TYPE")
lngBoundryPos = instr(1,strBoundry,"boundary=") + 8
strBoundry = "--" & right(strBoundry,len(strBoundry)-lngBoundryPos)
'Get first file boundry positions.
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
Do While lngCurrentEnd > 0
'Get the data between current boundry an
' d remove it from the whole.
strData = mid(strDataWhole,lngCurrentBegin, lngCurrentEnd - lngCurrentBegin)
strDataWhole = replace(strDataWhole,strData,"")

'Get the full path of the current file.
lngBeginFileName = instr(1,strdata,"filename=") + 10
lngEndFileName = instr(lngBeginFileName,strData,chr(34))
'Make sure they selected at least one fi
' le.
if lngBeginFileName = lngEndFileName and lngNumberUploaded = 0 Then

Response.Write "<H2> Ha ocurrido el siguiente error.</H2>"
Response.Write "Debes elegir un archivo para subir"
Response.Write "<BR><BR>Pulsa el botón volver, realiza la corrección."
Response.Write "<BR><BR><INPUT type='button' onclick='history.go(-1)' value='<< Volver' id='button'1 name='button'1>"
Response.End
End if
'There could be one or more empty file b
' oxes.
if lngBeginFileName <> lngEndFileName Then
strFilename = mid(strData,lngBeginFileName,lngEndFileName - lngBeginFileName)
'Creates a raw data file with data betwe
' en current boundrys. Uncomment for debug
' ing.
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set f = fso.OpenTextFile(server.mappath(".") & "\raw_" & lngNumberUploaded & ".txt", ForWriting, True)
'f.Write strData
'set f = nothing
'set fso = nothing

'Loose the path information and keep just the file name.
tmpLng = instr(1,strFilename,"\")
Do While tmpLng > 0
PrevPos = tmpLng
tmpLng = instr(PrevPos + 1,strFilename,"\")
Loop

FileName = right(strFilename,len(strFileName) - PrevPos)

'Get the begining position of the file data sent.
'if the file type is registered with the browser then there will be a Content-Type
lngCT = instr(1,strData,"Content-Type:")

if lngCT > 0 Then
lngBeginPos = instr(lngCT,strData,chr(13) & chr(10)) + 4
Else
lngBeginPos = lngEndFileName
End if
'Get the ending position of the file dat
' a sent.
lngEndPos = len(strData)

'Calculate the file size.
lngDataLenth = lngEndPos - lngBeginPos
'Get the file data
strFileData = mid(strData,lngBeginPos,lngDataLenth)
'Create the file.
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(server.mappath("imagenes") & "\" & FileName,ForWriting, True)
f.Write strFileData
Set f = nothing
Set fso = nothing

lngNumberUploaded = lngNumberUploaded + 1

End if

'Get then next boundry postitions if any
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
loop


Response.Write "Archivo subido <BR>"
Response.Write "El archivo ya está en el servidor.<BR>"
Response.Write "Por su seguridad será redireccionado al inicio.<BR>"
Response.Write "<BR><BR><INPUT type='button' onclick='document.location=" & chr(34) & "menumoder.asp" & chr(34) & "' value='<< Volver' id='button'1 name='button'1>"
End Select
%>
</BODY>
</HTML>
  #6 (permalink)  
Antiguo 19/09/2009, 21:10
Avatar de Fabu_dina  
Fecha de Ingreso: enero-2004
Mensajes: 425
Antigüedad: 21 años, 4 meses
Puntos: 1
Respuesta: Gestionar FTP mediante ASP

gracias pero ese codigo es para subir imagenes por medio de asp al servidor donde tienes alojada tu pagina yo lo que necesito es poderme conectar a un ftp externo a mi hospedaje

gracias de todas maneras
  #7 (permalink)  
Antiguo 19/09/2009, 21:12
Avatar de mc_quake  
Fecha de Ingreso: enero-2006
Ubicación: www.ecocargo.cl
Mensajes: 683
Antigüedad: 19 años, 3 meses
Puntos: 8
Respuesta: Gestionar FTP mediante ASP

http://www.example-code.com/asp/ftp.asp
__________________
Mc_Quake

Para ayudar en lo que se pueda:Zzz:
  #8 (permalink)  
Antiguo 21/09/2009, 11:56
Avatar de sjam7  
Fecha de Ingreso: diciembre-2001
Ubicación: Guadalajara, Mexico
Mensajes: 3.672
Antigüedad: 23 años, 4 meses
Puntos: 16
Respuesta: Gestionar FTP mediante ASP

para manejar los archivos tipo el explorardor? pues seria mas bien en JAVA no?
  #9 (permalink)  
Antiguo 21/09/2009, 12:44
Avatar de Fabu_dina  
Fecha de Ingreso: enero-2004
Mensajes: 425
Antigüedad: 21 años, 4 meses
Puntos: 1
Respuesta: Gestionar FTP mediante ASP

podria ser cualquier es para el cliente abierto


gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 12:40.