Arie
Arie

Reputation: 3583

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)

Upvotes: 2

Views: 2514

Answers (2)

Martin Prikryl
Martin Prikryl

Reputation: 202692

To retrieve attributes (including the last modification time) of a single file use Session.GetFileInfo method:

session.GetFileInfo(source).LastWriteTime

There's no way to retrieve "creation" time, just the "last modification" time.

Upvotes: 1

Xavier Peña
Xavier Peña

Reputation: 7919

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

Upvotes: 4

Related Questions