上传到FTP时保持图像创建日期 [英] Preserve image created date when uploading to FTP

查看:433
本文介绍了上传到FTP时保持图像创建日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想提出一个网站,我的家人在这里我们可以将图像并查看它们,但该网站的一个重要特点是日期,以便FX我姑姑当已经在我妈妈的生日,我也拍摄的照片进行排序拍摄的图像和我们上传他们将被添加到同一专辑等的图像。



我已经意识到,这是不可能通过上传时保留的时间浏览器。因此,我将做一个小程序,它仅用于上传图片。我有一个运行FTP服务器,但是当过我上传图片的日期将改为当前日期时间..的我已经找到了答案,为什么它是所以现在我正在寻找一种方式来保存,同时上传到FTP的日期。



下面是一些想法,我有:




  1. 如果该程序将文件添加到压缩文件并上传zip文件它们将保留日期,但这意味着我不得不具有解包拉链的服务器上的东西。

  2. 当图像被上传程序提取从原始图像创建的日期和它添加到一个文本文件,该文件还上传,但会再次要求其改变上传的图片创建日期在服务器上的程序。

  3. 也许我上传的图片,然后更改上传图像创建日期从客户端?


解决方案


  • 也许我上传的图片,然后更改上传的图片来自客户端?



  • 创建日期

    在FTP协议中,使用 MFMT MDTM 命令来更新文件的修改时间,或 MFCT 更新文件的创建时间戳记,这取决于这些你的FTP服务器支持。



    其实他们都不是标准化








    虽然在.NET框架中的本地FTP实现(在的FtpWebRequest Web客户端包装),不支持任何这些。



    您必须使用第三方库。



    例如中的 WinSCP赋予.NET程序集自动保存的修改时间任何上传(或下载)无需任何额外的代码。



    一个简单的示例代码上传文件(隐式保留修改时间):

      //设置会话选项
    sessionOptions sessionOptions =新SessionOptions
    {
    协议= Protocol.Ftp,
    主机名=example.com,
    用户名=用户,
    密码=输入mypassword
    };

    使用(会话的会话=新的Session())
    {
    //连接
    session.Open(sessionOptions);

    //上传
    session.PutFiles(@D:\toupload\image.jpg,/ home / user中/)检查();
    }

    有关详细信息,请参阅的 Session.PutFiles



    WinSCP赋予GUI的FTP客户端的最新版本(5.8.2和更新版本)甚至可以生成的C#代码为你



    (我的WinSCP的作者)


    So I am making a website for my family where we can upload our images and view them, but an important feature of the website is to sort by date so that when fx my aunt have taken pictures at my mothers birthday and I also have taken pictures and we upload the images they will be added to the same album etc.

    I've realized that it is not possible to preserve the date when uploading through a browser. So I will make a small program which is only used for upload pictures. I have an ftp server running but when ever I upload images the date will change to current datetime.. I have found the answer to why it does that so now I am looking for a way to preserve the date while uploading to FTP.

    Here's some ideas I've had:

    1. If the program adds the files to a zip file and upload that zip file they will preserve the date, but that means I would have to have something on the server that unpacks the zips.
    2. When the images gets uploaded the program extracts the created date from the original image and adds it to a text file which it also uploads, but that would again require a program on the server which changes the uploaded images created date.
    3. Maybe I upload the images and thereafter change the uploaded images created date from the client?

    解决方案

    1. Maybe I upload the images and thereafter change the uploaded images created date from the client?

    In FTP protocol, use MFMT or MDTM command to update file modification timestamp, or MFCT to update file creation timestamp, depending on which of these your FTP server supports.

    Actually none of them is standardized.

    • The MFMT and MFCT are drafted here: https://tools.ietf.org/html/draft-somers-ftp-mfxx-04
    • The MDTM is defined in RFC 3659 to retrieve file modification timestamp, using MDTM filename syntax. But many FTP servers support an alternative (non-standard) syntax MDTM filename timestamp (i.e. the same as proposed MFMT) to update the modification timestamp too.

    Though the native FTP implementation in .NET framework (the FtpWebRequest or the WebClient wrapper), does not support any of these.

    You have to use a 3rd party library.

    For example the WinSCP .NET assembly preserves the modification timestamp automatically for any upload (or download) without any additional code.

    A simple example code to upload a file (implicitly preserving the modification timestamp):

    // Setup session options
    SessionOptions sessionOptions = new SessionOptions
    {
        Protocol = Protocol.Ftp,
        HostName = "example.com",
        UserName = "user",
        Password = "mypassword",
    };
    
    using (Session session = new Session())
    {
        // Connect
        session.Open(sessionOptions);
    
        // Upload
        session.PutFiles(@"d:\toupload\image.jpg", "/home/user/").Check();
    }
    

    For details, see Session.PutFiles.

    The latest version of WinSCP GUI FTP client (5.8.2 and newer) can even generate the C# code for you.

    (I'm the author of WinSCP)

    这篇关于上传到FTP时保持图像创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆