Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Delete files from the remote server

$
0
0

hi,

I have found the code for deleting filed from the remote server but there is small change in my requirement.

i have four different files which will moving to this folder ("Archieve" )daily with the time stamp in the remote folder and i need to delete files older than 60 days....

four files will be  in this format

"fl_principals_20120815","fl_teachers_20120815","fl_Students_20120815","dw_semesters_20120815"

can you check the code............where do i need to change  in the code...

Public Sub Main()

    Try
      Dim request As System.Net.FtpWebRequest
      request = System.Net.WebRequest.Create("ftp://remoteurl.com/remotefolder/")
      request.Method = System.Net.WebRequestMethods.Ftp.ListDirectoryDetails

      request.Credentials = New System.Net.NetworkCredential("username", "password")

      Dim response As System.Net.FtpWebResponse
      response = request.GetResponse()

      Dim responseStream As System.IO.Stream
      responseStream = response.GetResponseStream()

      Dim reader As System.IO.StreamReader = New System.IO.StreamReader(responseStream)

      While Not reader.EndOfStream
        Dim strTemp As String = reader.ReadLine
        Dim fileName = strTemp.Substring(strTemp.IndexOf("_") - 3)
        Dim theDate As DateTime = DateTime.ParseExact(fileName.Substring(4,8), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture)
        If (theDate.Date < DateTime.Now.AddDays(-60).Date) Then
          request = System.Net.WebRequest.Create("ftp://remoteurl.com/remotefolder/"+fileName)
          request.Method = System.Net.WebRequestMethods.Ftp.DeleteFile
          request.Credentials = New System.Net.NetworkCredential("username", "password")

          response = request.GetResponse()
        End If

      End While


      reader.Close()
      response.Close()
    Catch ex As Exception
      Dts.TaskResult = ScriptResults.Failure
    End Try

		Dts.TaskResult = ScriptResults.Success
	End Sub

thanks,

aravind-



Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>