Search code examples
vb.netuploading

How to replace a file that uploading a new file to ftp server using VB.NET


Dim MkFile As System.Net.FtpWebRequest = _ DirectCast(System.Net.WebRequest.Create(FtppathBase & SavePath), System.Net.FtpWebRequest)

    MkFile.Credentials = New System.Net.NetworkCredential("username", "password")
    MkFile.Method = System.Net.WebRequestMethods.Ftp.UploadFile
    MkFile.Timeout = 10000000
    MkFile.ReadWriteTimeout = 10000000
    MkFile.KeepAlive = True
    Dim bFile() As Byte = System.IO.File.ReadAllBytes(FileRcrs)
    Dim UpStream As System.IO.Stream = MkFile.GetRequestStream()
    UpStream.Write(bFile, 0, bFile.Length)
    UpStream.Close()
    UpStream.Dispose()

im using this method . but its not overwrite the file . please help me to overwrite a file


Solution

  • You could delete the file if it exists prior to uploading the new one.

    It's not the cleanest answer but its easy and should work.