Reply to thread

Try the following code, it has worked for me recently:

[code]

 Allow a file to be uploaded to a web server using FTP.

    Public Shared Function uploadFileUsingFTP(ByVal CompleteFTPPath As String, ByVal CompleteLocalPath As String, Optional ByVal UName As String = "", Optional ByVal PWD As String = "") As String

        uploadFileUsingFTP = Nothing


        Dim resultMsg As String = "Upload complete"

        Try

            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 System.IO.FileStream = System.IO.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


            Return resultMsg


        Catch ex As Exception

            resultMsg = ex.Message

        End Try

    End Function

[/code]


[code]

myFtp.uploadFileUsingFTP("ftp://yahoo.com/abc/about.txt", _

                                            System.IO.Path.GetFullPath(FileUpload1.FileName).ToString, _

                                                "username", "password")

[/code]


The first parameter that you pass is the target location and the new file name.


Mike55.


Back
Top