Visualizzazione dei risultati da 1 a 4 su 4

Discussione: ftp upload

  1. #1

    ftp upload

    Buonasera,
    premetto che sono completamente digiuno di ASP.NET.

    Per bypassare i limiti imposti dai server agli upload via http ho pensato di usare il protocollo FTP.

    Mi sono imbattuto in uno script ASP.NET che sembra fare al caso mio:

    codice:
    Imports System.IO
    Imports System.Net
    
    Partial Class _Default
        Inherits System.Web.UI.Page
    
    	Protected Sub cmdUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdUpload.Click
    		'On button Click call the function 
    		'and Pass Parameter Values
    		'Display Message on Success
    		uploadFileUsingFTP("ftp://ftp.MIODOMINIO.it/public/up/code.txt","L:\code.txt")
    		lblMsg.Text = "File Uploaded Successfully :)"
    	End Sub
    
    	Public Sub uploadFileUsingFTP(ByVal CompleteFTPPath As String, ByVal CompleteLocalPath As String, Optional ByVal UName As String = "MIALOGIN", Optional ByVal PWD As String = "MIAPASSWORD")
    		'Create a FTP Request Object and Specfiy a Complete Path 
    		Dim reqObj As FtpWebRequest = WebRequest.Create(CompleteFTPPath)
    		'Call A FileUpload Method of FTP Request Object
    		reqObj.Method = WebRequestMethods.Ftp.UploadFile
    		'If you want to access Resourse Protected You need to give User Name and PWD
    		reqObj.Credentials = New NetworkCredential(UName, PWD)
    		'FileStream object read file from Local Drive
    		Dim streamObj As FileStream = File.OpenRead(CompleteLocalPath)
    		'Store File in Buffer
    		Dim buffer(streamObj.Length) As Byte
    		'Read File from Buffer
    		streamObj.Read(buffer, 0, buffer.Length)
    		'Close FileStream Object Set its Value to nothing
    		streamObj.Close()
    		streamObj = Nothing
    		'Upload File to ftp://localHost/ set its object to nothing
    		reqObj.GetRequestStream().Write(buffer, 0, buffer.Length)
    		reqObj = Nothing
    	End Sub
    End Class
    Ho fatto vari tentativi ma ricevo sempre l'errore:
    Could not find a part of the path 'L:\code.txt'.

    Line 23: Dim streamObj As FileStream = File.OpenRead(CompleteLocalPath)

    Ho provato varie path ma l'errore è sempre lo stesso, qualcuno saprebbe indicarmi una soluzione?

    Buon Agosto
    Luca

  2. #2

  3. #3
    Utente di HTML.it L'avatar di mexican
    Registrato dal
    Oct 2001
    residenza
    cava de tirreni
    Messaggi
    3,541
    Originariamente inviato da lucavizzi
    posto il link alla fonte dello script:
    http://www.devasp.net/net/articles/display/280.html
    se è aruba il tuo host: ftp://localhost/localhost/ftp1.txt"

  4. #4
    La soluzione corretta per "baypassare" il limite non è questa.

    E' molto più semplice,devi modificare il web.config:

    codice:
        <system.web>
            <httpRuntime executionTimeout=”110″ maxRequestLength=”20000″ />
        </system.web>
    nell'esempio ho impostato il limite per l'upload su circa 20 MB, tu dovresti fare la stessa cosa

    Chi sbaglia, apprende meglio di chi non ha mai commesso errori.
    DOT.NET Addicted since 2006 (My Blog)

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 © 2026 vBulletin Solutions, Inc. All rights reserved.