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

Asked

Viewed 837 times

-1

I am using framework 4.5 and would like to know how to get the date and time of creation of 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 read permission from folder and file, SFTP user and password.

2 answers

1

First, you don’t need an extra component to do the operations listed in the pho3nix, it is possible to do everything with the . "pure" NET, even more a simple operation like the one you want. What’s more, the package Ftp.dll is paid, maybe you haven’t noticed this, but just enter their site that you can 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 a License.

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

  • FTPS is the FTP protocol with the addition of SSL, for security.

  • SFTP (SSH File Transfer Protocol/Secure File Transfer Protocol) is an extension of SSH that provides file transfer capability.

In this case, you will even need an extra package to assist. I found the SSH.NET, It has not been touched for a long time, but it is open source and it is possible to make the most of it. I tested it using my server and it worked well, here’s an example of how to do

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

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

    sftp.Disconnect();
}

Maybe you’ll be interesting search for some package in nuget

0

You will need to use a Ftp

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();
}
  • I tried to use this code but it gives exception with error O nome solicitado é válido, mas não foram encontrados dados do tipo solicitado on the line client.Connect("ftp.example.org"), you know what can be ?

  • This may be a stupid question but you have switched from ftp.example.org to your ftp?

  • I switched yes, I put my ftp and even saw that the method Connect has one of the parameters to put the port and I put the port to access my ftp

  • I’m sorry about the question, but it happens all the time. Actually I think you have to use Connectssl ( //or Connectssl for SSL) because it is an SFTP

  • No problem. So... even though it didn’t work, it gave the same error I used Connectssl and it didn’t work, I even tried to use Beginconnect() but tbm didn’t work.

  • I just tested on my pc and with my ftp this ok.

  • 1

    I think it is valid to remember that this component is paid for. And also that it is possible to do this without it, which your answer does not explain.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.