Click here to Skip to main content
12,831,554 members (29,603 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
i want to upload a file from fileupload control but insted of using http i want to use ftp... can any one help me out? thanks in advance...
Posted 15-Mar-12 4:12am
Naikniket1.1K
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Hi,

Me too came across same situation, and bit of R&D leads me to the following solution.
On a simple form there is a FileUpload control (say FileUpload1) and a Button Control (say Button1). On Click event of button write following code

     Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
         Dim f as bool = Upload(FileUpload1.FileBytes, FileUpload1.FileName, "abcftp", "abc@ftp", "ftp://ftp.someftp.com")
         Response.Write(f = True, "Uploaded Successfully", "Unable to Upload")
     End Sub


Upload() function does all the magic
         Public Function Upload(FileByte() As Byte, FileName As String, ftpUserID As String, ftpPassword As String, ftpURL As String) As Boolean
            Dim retValue As Boolean = False
            Try
                Dim ftpFullPath As String = ftpURL + "/" + FileName
                Dim ftp As FtpWebRequest = FtpWebRequest.Create(New Uri(ftpFullPath))
                ftp.Credentials = New NetworkCredential(ftpUserID, ftpPassword)
                ftp.KeepAlive = True
                ftp.UseBinary = True
                ftp.Method = WebRequestMethods.Ftp.UploadFile
                Dim ftpStream As Stream = ftp.GetRequestStream()
                ftpStream.Write(FileByte, 0, FileByte.Length)
                ftpStream.Close()
                ftpStream.Dispose()
                retValue = True
            Catch ex As Exception
                Throw ex
            End Try
            Return retValue
        End Function


I hope this will help.
Thanks.
  Permalink  
Comments
   
Dim f as bool ?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Member 11073820 22-Dec-15 7:22am
   
THANKS IT IS WORKING FINE

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170326.1 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100