Avatar of RayT
RayT
Flag for United States of America

asked on 

Sending a file using FTP

I'm trying to send a file using the following block of code.  How do I send a file to a specific folder on the server using this code?

' Sample Call
dim sourceFileName as string
dim targetfileName as uri

SendFile(sourceFileName, targetfileName)

   Shared Sub SendFile(sourcefileName As String, targetfileName As Uri)
      request = DirectCast(FtpWebRequest.Create(targetfileName), FtpWebRequest)

      With request
         .Method = WebRequestMethods.Ftp.UploadFile
         .UsePassive = True
         .UseBinary = True
         .KeepAlive = True
      End With

      Using fileStream As FileStream = File.OpenRead(sourcefileName)
         Dim buffer As Byte() = New Byte(fileStream.Length - 1) {}

         fileStream.Read(buffer, 0, buffer.Length)

         With request.GetRequestStream()
            .Write(buffer, 0, buffer.Length)
            .Close()
         End With

         response = request.GetResponse
      End Using
   End Sub

Open in new window

.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
RayT

8/22/2022 - Mon