User-1735938375 posted
I am using the following code. I have already try to pass
ftp://myFTPserver.com/Go.Data72.CLEVDATA/ to constructor, its is not working.
Dim ftpUsername As String
Dim ftpPassword As String
Dim credential As NetworkCredential
Dim request As FtpWebRequest
Dim reader As FileStream
Dim stream As Stream
Dim response As FtpWebResponse
Dim Source As String="C:\Lakhan\abc.txt"
Dim Target As String = "ftp://myFtpServer/GO.$DATA72.CLEVDATA/abc.txt"
Try
ftpUsername = ConfigurationManager.AppSettings("FTPUsername").ToString()
ftpPassword = ConfigurationManager.AppSettings("FTPPassword").ToString()
'Upload file on FTP server
'My.Computer.Network.UploadFile(Source, Target, ftpUsername, ftpPassword)
credential = New NetworkCredential(ftpUsername, ftpPassword)
request = DirectCast(WebRequest.Create(Target), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.UploadFile
request.Credentials = credential
reader = New FileStream(Source, FileMode.Open)
Dim buffer(Convert.ToInt32(reader.Length - 1)) As Byte
reader.Read(buffer, 0, buffer.Length)
reader.Close()
request.ContentLength = buffer.Length
stream = request.GetRequestStream
stream.Write(buffer, 0, buffer.Length)
stream.Close()
response = DirectCast(request.GetResponse, FtpWebResponse)
response.Close()
Catch ex As Exception
'Throw the exception to skip the further processing of this file
Throw New Exception(String.Concat(New String() {"Error in UploadFileToFTP: ", ex.Message}))
End Try
Thanks,
Lakhan