所以我正在为我的家人创建一个网站,我们可以在其中上传我们的图像并查看它们,但该网站的一个重要功能是按日期排序,以便例如当我的阿姨在我母亲的生日和我也拍了照片,我们上传它们将添加到同一个相册等的图像.
我意识到通过浏览器上传时无法保留日期.所以我会做一个只用于上传图片的小程序.我有一个 FTP 服务器正在运行,但是当我上传图像时,日期将更改为当前日期时间.我找到了为什么这样做的答案 所以现在我正在寻找一种在上传到 FTP 时保留日期的方法.
以下是我的一些想法:
- 也许我上传了图片,然后从客户端更改了上传图片的创建日期?
在 FTP 协议中,使用 MFMT
或 MDTM
命令更新文件修改时间戳,或 MFCT
更新文件创建时间戳,具体取决于哪个您的 FTP 服务器支持的这些.
实际上没有一个是标准化的.
MFMT
和 MFCT
在此起草:MDTM
在 RFC 3659 中定义为检索文件修改时间戳,使用 MDTM 文件名
语法.但许多 FTP 服务器也支持替代(非标准)语法 MDTM 文件名时间戳
(即与提议的 MFMT
相同)来更新修改时间戳.尽管 .NET 框架中的本机 FTP 实现(FtpWebRequest
或 WebClient
包装器)不支持其中任何一个.
您必须使用第 3 方库.
例如,WinSCP .NET 程序集会自动为任何上传(或下载),无需任何额外代码.
上传文件的简单示例代码(隐式保留修改时间戳):
//设置会话选项SessionOptions sessionOptions = 新的 SessionOptions{协议 = Protocol.Ftp,主机名 = example.com",用户名 = 用户",密码=我的密码",};使用(会话会话 = 新会话()){//连接session.Open(sessionOptions);//上传session.PutFiles(@"d: ouploadimage.jpg", "/home/user/").Check();}
有关详细信息,请参阅 Session.PutFiles
.p>
最新版本的 WinSCP GUI FTP 客户端(5.9 及更高版本)甚至可以生成 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 for example 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:
- 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.
MFMT
and MFCT
are drafted here: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: ouploadimage.jpg", "/home/user/").Check();
}
For details, see Session.PutFiles
.
The latest version of WinSCP GUI FTP client (5.9 and newer) can even generate the C# code for you.
(I'm the author of WinSCP)
这篇关于上传到 FTP 时保留图像创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!