Click here to Skip to main content
14,668,709 members
Rate this:
Please Sign up or sign in to vote.
See more:
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...

Rate this:
Please Sign up or sign in to vote.

Solution 3


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", "")
    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
        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)
        retValue = True
    Catch ex As Exception
        Throw ex
    End Try
    Return retValue
End Function

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

Solution 1

Member 11073820 22-Dec-15 7:22am

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

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