Visualizzazione dei risultati da 1 a 9 su 9
  1. #1

    eliminare un file in server remoto

    Ciao,
    ho un accesso FTP a una cartella in remoto dove ci sono dei file CSV da importare, ho trovato un componente FREE che mi permette il metodo GET per fare il download del file sul mio server, ma -essendo free- ha solo i metodi PUT & GET.
    Dopo che ho importato il file nel mio DB ho la necessità di cancellare il file CSV, esiste un modo per farlo senza usare un componente? Che so, con File System Object (ma non credo), boh!?

    Grazie e ciao.

  2. #2

  3. #3
    Grazie per il link ma credo non mi sia spiegato molto bene,
    cioè posso usare FSO anche per eliminare un file su un server a cui ho solo accesso ftp?
    Cioè le pagine ASP non stanno girando sulla macchina dove devo cancellare il file.
    Ho fatto un tentativo del genere..

    dim fs
    Set fs=Server.CreateObject("Scripting.FileSystemObject ")
    fs.DeleteFile("ftp://12.345.67.890/NomeCartella/File.Csv")
    set fs=nothing

    Risultato:

    Errore di run-time di Microsoft VBScript error '800a0034'

    Nome o numero di file non valido

    test.asp, line 4

  4. #4
    Utente bannato
    Registrato dal
    Jun 2004
    Messaggi
    1,854
    figurati se puoi fare una cosa del genere :P

  5. #5

  6. #6
    effettivamente immaginavo, nella disperazione avevo provato anche un

    fs.DeleteFile("ftp://usernameassword@ftp.pippo.it/File.Csv")

    quindi!? altre soluzioni?

    sapete se per caso ci sono componenti (possibilmente FREE) che hanno come metodo ftp anche il delete?

    ciao

  7. #7
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Ma se metti una pagina sul server non fai prima?

    Roby

  8. #8
    Utente di HTML.it L'avatar di Baol74
    Registrato dal
    Jul 2002
    Messaggi
    2,004
    Sicuramente la soluzione di roby è la più veloce.

    Un'altra soluzione è usare ftp.exe.
    Se puoi usare aspExec o WShell, lanciando ftp.exe hai tutti i comandi che vuoi.

    Questo è uno script che usa WScript e ftp.exe per fare un upload

    codice:
    <%@ 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)
    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"
    
    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, "
    ", 1, -1, 1) )
    %>

  9. #9
    Grazie a tutti
    Ho finalemente trovato il componente che fa per me!

    Il mio problema era cancellare un file su un server dove un ns partner mi avevo dato solo i permessi in lettura e scrittura per uno scambio dati, non è che posso mettere della pagine asp sul suo server.

    Se a qualcuno può interessare c'è un bel componente FTP per ASP FREE con tanti metodi, incluso il DELETE che mi serviva

    http://www.chilkatsoft.com/ChilkatFtp.asp

    La documentazione non è il massimo, ma per essere gratis è più che sufficiente, ho arrangiato una cosa del genere.. funzia!

    <%
    set oFTP = Server.CreateObject("ChilkatFTP.ChilkatFTP")
    oFTP.HostName = "000.000.000.00"
    oFTP.Username = "pinco"
    oFTP.Password = "pallino"
    oFTP.Connect()
    oFTP.DeleteRemoteFile("nomefile.Csv")
    oFTP.Disconnect()
    Set oFTP = Nothing
    %>




    Ciao e grazie mille!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.