How to get the date of creation of a file that is on an FTP server c #

0
I'm using framework 4.5 and would like to know how to get the date and time of creating a file that is on an SFTP server, do not want to download it, just know the date and time it was created.

I have permission to read the folder and file, the SFTP user and password.

    
asked by anonymous 15.06.2016 / 21:30

2 answers

1

First, you do not need an extra component to do the pho3nix response operations, you can do everything with "pure" .NET, yet another simple operation like the one you want. What's more, the Ftp.dll package is paid , you may not have noticed this, but just go to their website and see the following message. >

  

This download is fully functional trial. It has the same features as the registered version. The evaluation version of the component displays "Please purchase a license" dialog. Some uploaded files will have their name changed. To remove this limitation you'll need to purchase the license.

Second, the answer is wrong, at least according to the description of your question. SFTP and FTPS are two completely different things. Briefly:

  • FTPS is the FTP protocol with the addition of SSL for security.
  • SFTP (SSH File Transfer Protocol) is an SSH extension that provides file transfer capability.

In this case, you will even need an extra package to help. I found the SSH.NET , it has been a long time that it is not tweaked but it is open source and you can get the most out of it of his profit. I tested it using my server and it worked fine, here is an example of how to do

using (var sftp = new SftpClient(servidor, porta, usuario, senha))
{
    sftp.Connect();

    DateTime data = sftp.GetLastWriteTime("caminhoDoArquivoNoServidor");

    sftp.Disconnect();
}

It may be interesting to search for a package in nuget

    
16.06.2016 / 04:45
0

You'll need to use a Ftp component

to install:

Install-Package Ftp.dll

Then in your code

// C# version

using (Ftp client = new Ftp())
{
    client.Connect("ftp.example.org");    // or ConnectSSL for SSL
    client.Login("user", "password");

    List<FtpItem> items = client.GetList();

    foreach (FtpItem item in items)
    {
        Console.WriteLine("Name:        {0}", item.Name);
        Console.WriteLine("Size:        {0}", item.Size);
        Console.WriteLine("Modify date: {0}", item.ModifyDate);

        Console.WriteLine("Is folder:   {0}", item.IsFolder);
        Console.WriteLine("Is file:     {0}", item.IsFile);
        Console.WriteLine("Is symlink:  {0}", item.IsSymlink);

        Console.WriteLine();
    }

    client.Close();
}
    
15.06.2016 / 21:35