获得文件大小在C#中的FTP

编程入门 行业动态 更新时间:2024-10-24 20:20:48
本文介绍了获得文件大小在C#中的FTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想上的FTP文件的大小。

I want to get the size of a file on an FTP.

//Get File Size reqSize = (FtpWebRequest)FtpWebRequest.Create(new Uri(FtpPath + filePath)); reqSize.Credentials = new NetworkCredential(Username, Password); reqSize.Method = WebRequestMethods.Ftp.GetFileSize; reqSize.UseBinary = true; FtpWebResponse respSize = (FtpWebResponse)reqSize.GetResponse(); long size = respSize.ContentLength; respSize.Close();

我曾尝试以下,但得到一个550错误。未找到文件/无法访问。但是,下面的代码工作...

I have tried the following but get a 550 error. File not found / no access. However, the following code works...

reqTime = (FtpWebRequest)FtpWebRequest.Create(new Uri(FtpPath + filePath)); reqTime.Credentials = new NetworkCredential(Username, Password); reqTime.Method = WebRequestMethods.Ftp.GetDateTimestamp; reqTime.UseBinary = true; FtpWebResponse respTime = (FtpWebResponse)reqTime.GetResponse(); DateTime LastModified = respTime.LastModified; respTime.Close();

编辑:这是不是为我工作的原因是,我的FTP服务器不支持该尺寸的方法。

推荐答案

尝试 reqSize.Method = WebRequestMethods.Ftp.GetFileSize ; ,而不是GetDateTimestamp

Try reqSize.Method = WebRequestMethods.Ftp.GetFileSize; instead of GetDateTimestamp

这为我工作:

FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://servername/filepath")); request.Proxy = null; request.Credentials = new NetworkCredential("user", "password"); request.Method = WebRequestMethods.Ftp.GetFileSize; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); long size = response.ContentLength; response.Close();

更多推荐

获得文件大小在C#中的FTP

本文发布于:2023-11-07 22:38:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567629.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件大小   FTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!