Hi All,
I am facing a problem in Ziping any file and then sending it to another server through FTP.
What I have to actually do is to retrive the property of files of any directory and then find out the last 24 hours modified files. Then copy it into another directory which named as the current system date. Then Zip that folder in which the last 24 hours modified files are present and then FTP to another server.
I have done almost part but unable to rename the folder as current system time and FTP part.
Plz help me regarding this as soon as possible.here is the code what i have written.
I am facing a problem in Ziping any file and then sending it to another server through FTP.
What I have to actually do is to retrive the property of files of any directory and then find out the last 24 hours modified files. Then copy it into another directory which named as the current system date. Then Zip that folder in which the last 24 hours modified files are present and then FTP to another server.
I have done almost part but unable to rename the folder as current system time and FTP part.
Plz help me regarding this as soon as possible.here is the code what i have written.
Code:
Imports System
Imports System.IO
Imports System.Data
Imports System.IO.Compression
Imports system.IO.Compression.GZipStream
Public Class MainClass
Shared Sub Main()
Dim Now As DateTime = DateTime.Now
Console.WriteLine("Todays time is" & DateTime.Now.AddDays(0))
Console.WriteLine("yeasturday Date is" & DateTime.Now.AddDays(-1))
Dim myDirectory As DirectoryInfo
myDirectory = New DirectoryInfo("C:\reg")
Dim aFile As FileInfo
For Each aFile In myDirectory.GetFiles
Console.WriteLine("The file named " & aFile.FullName)
Console.WriteLine("The Creation Time is" & aFile.CreationTime)
Console.WriteLine("The Last Modified Time is" & aFile.LastAccessTime)
Next
For Each aFile In myDirectory.GetFiles
If (DateTime.Now.AddDays(-1).ToString <= aFile.LastAccessTime) Then
aFile.CopyTo("C:\Arvind" & "\" & aFile.Name)
Console.WriteLine(aFile.FullName & " File has been last modified in the past 24 hours at" & aFile.LastAccessTime)
System.IO.Directory.Move("C:\Arvind", "Current System time")
Console.WriteLine("Files has been renamed")
End If
Dim s As ICSharpCode.SharpZipLib.Zip.ZipOutputStream = New ICSharpCode.SharpZipLib.Zip.ZipOutputStream(System.IO.File.Create("C:\testfile2.zip"))
s.SetLevel(9) ' 0-9, 9 being the highest level of compression
Dim buffer() As Byte
ReDim buffer(4096)
Dim filenames As String() = Directory.GetFiles("C:\DataTime.now")
Dim f As String
For Each f In filenames
Dim entry As ICSharpCode.SharpZipLib.Zip.ZipEntry = New ICSharpCode.SharpZipLib.Zip.ZipEntry(Path.GetFileName(f))
entry.DateTime = DateTime.Now
s.PutNextEntry(entry)
Dim fs As FileStream = System.IO.File.OpenRead(f)
Dim sourceBytes As Integer = 1
Do Until (sourceBytes <= 0)
sourceBytes = fs.Read(Buffer, 0, Buffer.Length)
s.Write(Buffer, 0, sourceBytes)
Loop
fs.Close()
Next
clean up
s.Finish()
s.Close()
Next
End Sub
End Class
Comment