Recuerde que para que funcione este script deberá autenticar con su usuario y clave de FTP en el web.config para tener permisos de escritura.
Código de autenticación de usuario y clave del FTP:
|
| |
|
|
|
<?xml version="1.0"?>
<configuration>
<system.web>
<identity impersonate="true" userName="USUARIO" password="CLAVE"/>
..... |
|
|
|
|
| |
| El código del File Upload: |
| |
|
|
|
<script language="VB" runat=server>
Sub DoUpload(Sender As Object, e As System.EventArgs)
Dim sPath as String
Dim sFile as String
Dim sFullPath as String
Dim sSplit() as String
Dim sPathFriendly as String
' Sube el archivo a la misma ruta donde esta el script
sPath = Server.MapPath(".")
If Right(sPath, 1) <> "\" then
sPathFriendly = sPath 'Esta es la ruta que mostrara
sPath = sPath & "\"
Else
sPathFriendly = Left(sPath, Len(sPath) - 1)
End If
' Va a grabar el archivo con el mismo nombre que el de subida
'El codigo debajo obtiene el nombre del archivo
'(Saca la informacion de la ruta)
sFile = txtUpload.PostedFile.FileName
sSplit = Split(sFile, "\")
sFile = sSplit(Ubound(sSplit))
sFullPath = sPath & sFile
Try
txtUpload.PostedFile.SaveAs(sFullPath)
lblResults.Text = "Se subi el archivo " & sFile & " to " & sPathFriendly & " con xito."
Catch Ex as Exception
lblResults.Text = "La subida del archivo " & sFile & " a " & sPathFriendly & " Fall por el siguiente motivo: " & Ex.Message
Finally
lblResults.Font.Bold = True
lblResults.Visible = true
End Try
End Sub
</script>
<html>
<body>
<form enctype="multipart/form-data" runat=server>
<FONT face = +1><B>
Seleccione el Archivo a subir:</b></FONT>
<input id="txtUpload" type=file runat=server>
<P align = CENTER>
<asp:button id=btnUpload Text="Subir Archivo" OnClick="DoUpload" runat=server/>
<hr noshade>
<asp:label id="lblResults" Visible=false runat=server/>
</form>
</body>
</html> |
|
|
|
|
| |