Reply to thread

I guess it was a little late while I was trying.

I had the impression WebRequest.Create would just open a connection to the FTPServer,

but it also has to point to the file to which it should be uploaded.


I should have noticed ealier since my code doesnt tell

the FTP Server to which file it should upload. :rolleyes:


My new code:

[code=vb]        Public Shared Function TextUpload(ByVal Host As String, ByVal Port As UInt16, ByVal UserName As String, ByVal Password As String, ByVal SourceStr As String, ByVal FileName As String) As Boolean

            Dim FTPCon As FtpWebRequest


            FTPCon = WebRequest.Create(Host & ":" & Port & "/" & FileName)

            FTPCon.Method = WebRequestMethods.Ftp.UploadFile

            FTPCon.Credentials = New NetworkCredential(UserName, Password)


            Dim FileContent() As Byte = Encoding.ASCII.GetBytes(SourceStr)

            FTPCon.ContentLength = FileContent.Length

            Try

                Dim ReqStream As Stream = FTPCon.GetRequestStream

                ReqStream.Write(FileContent, 0, FileContent.Length)

                ReqStream.Close()


                Dim FTPRes As FtpWebResponse = FTPCon.GetResponse


                Return True


            Catch ex As Exception

                Return False

            End Try

        End Function

[/code]


Back
Top