Search code examples
.netvb.netftpwinscpwinscp-net

WinSCP get file creation date


I am using WinSCP for .NET library. I am facing some problems which I cannot resolve since almost day. What I would like to achieve is to get file name creation date. Do you know how can achieve that? I am completely stack.

Tried like this but unfortunately source contains not whole path to ftp folder like

C:\folder1\folder2\file

but it takes folder2 as root ftp folder

session.GetFiles(source, destination, removeSource).Check()

If I would have entire path to file I would just simple use:

File.GetCreationTime(source)

Solution

  • Is this what you are looking for?

    Dim sessionOptions As New WinSCP.SessionOptions With { ... initialize your ftp parameters here ... }
    
    Using session As WinSCP.Session = New WinSCP.Session
    
        session.Open(sessionOptions)
    
        Dim fileInfos As WinSCP.RemoteDirectoryInfo = session.ListDirectory(ftpFolder)
    
        For Each ftpFile As WinSCP.RemoteFileInfo In fileInfos.Files
            ' Here you get the file date:
            Dim fileDate As Date = ftpFile.LastWriteTime
        Next
    
    End Using