Tag: ftpwebresponse

FtpWebResponse,操作超时

我想根据他们的日期时间从ftp服务器下载文件..我可以从CuteFtp第三方访问这个Ftp,而且每件事都是Okey ..但是当我在GetRespone()行运行下面的代码时,我收到此错误:操作已经超时。 我用webclient requet以编程方式从这个FTP下载了一个示例文件,它很好..但是我需要使用FtpWebRequest来获取listDirectoryDe​​tail而webClient不支持那个……还有一件事,请求中有一个exception: FtpWebRequest.ContentType抛出了System.NotSupportedException类型的exception。 这是我的代码: Uri uri = new Uri(“ftp://192.168.1.5:2100/”);//the private address if (uri.Scheme != Uri.UriSchemeFtp) { return; } FtpWebRequest reqFTP; reqFTP = (FtpWebRequest)WebRequest.Create(uri); reqFTP.Credentials = new NetworkCredential(“myuser”, “mypass”); reqFTP.KeepAlive = false; reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails; reqFTP.UseBinary = true; reqFTP.Proxy = null; reqFTP.UsePassive = false; FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); 请帮忙 :(

StreamReader ReadLine抛出处置exception而不是返回null

我正在尝试从FTP服务器获取文本文件,然后逐行读取它,将每行添加到列表中。 我的代码似乎符合以下标准模式: var response = (FtpWebResponse)request.GetResponse(); using (var responseStream = response.GetResponseStream()) { using (var reader = new StreamReader(responseStream)) { string line; while((line = reader.ReadLine()) != null) { lines.Add(line); } } } 但是,出于某种原因,当在文件的最后一行调用reader.ReadLine()时,它会抛出一个exception,说“无法访问已处置的对象”。 这真的让我很烦恼。 如果我没记错的话,当没有其他数据时,流的最后一行是null ,对吧? 另外(虽然我不确定这一点),这似乎只在当地发生; 这项服务的现场版本似乎正在顺利进行(虽然有些问题我试图深究)。 我当然不会在日志中看到这个问题。 有人有想法吗? 编辑:这是例外的全文。 System.ObjectDisposedException: Cannot access a disposed object. Object name: ‘System.Net.Sockets.NetworkStream’. at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 […]

从WebRequestMethods.Ftp.ListDirectoryDe​​tails中提取文件名

我有一个应用程序执行以下操作:目录列表,下载文件,全部下载。 从WebRequestMethods.Ftp.ListDirectoryDe​​tails获取文件名时遇到问题。 对于每种情况,似乎都不可能这样做。 WebRequestMethods.Ftp.ListDirectoryDe​​tails以下列方式返回lineItem: “-rw-r – r– 1 ftp ftp 39979 Aug 01 16:02 db to pc 2014-08-05 07-30-00.csv” 我正在使用第一个字符来确定它是文件还是目录。 然后我在空间上拆分文件,并在拆分中的固定索引量之后获取文件名。 我的实现中的问题是,如果一个文件有多个空格,那么它将被错误地引用,空格较少,并且在尝试下载时不会找到该文件。 我无法使用split.last(),因为文件名可以包含空格,也不能包含WebRequestMethods.Ftp.ListDirectory,因为它不允许我们区分目录和没有扩展名的文件。 也不是正则表达式,因为文件名可以包含日期。 寻找完全涵盖所有案例的解决方案的任何帮助都会很棒。 bool isDirectory = line.Substring(0,1).Equals(“d”, System.StringComparison.OrdinalIgnoreCase); string[] itemNames = line.Split(new[] { ‘ ‘, ‘\t’ }, StringSplitOptions.RemoveEmptyEntries).Select((value, index) => new { value, index }).Where(i => i.index > 7).Select(i => i.value).ToArray(); string val […]

FtpWebRequest下载文件不正确的大小

我正在使用以下代码从远程ftp服务器下载文件: FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverPath); request.KeepAlive = true; request.UsePassive = true; request.UseBinary = true; request.Method = WebRequestMethods.Ftp.DownloadFile; request.Credentials = new NetworkCredential(userName, password); using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) using (Stream responseStream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(responseStream)) using (StreamWriter destination = new StreamWriter(destinationFile)) { destination.Write(reader.ReadToEnd()); destination.Flush(); } 我正在下载的文件是一个DLL,我的问题是它以某种方式被这个过程改变了。 我知道这是因为文件大小正在增加。 我怀疑这部分代码有错: destination.Write(reader.ReadToEnd()); destination.Flush(); 任何人都可以提出任何可能出错的想法吗?

使用凭据连接ftp服务器

我正在编写一个使用带有凭据的ftp服务器的程序。 我正在尝试从服务器检索目录列表但是当我到达该行时: string line = reader.ReadLine(); 我得到的字符串只包含:“无法打开”主机:/ lib1 \“。” 如果我尝试获取另一行,则抛出下一个exception:远程服务器返回错误:(550)文件不可用(例如,找不到文件,没有访问权限)。 我肯定(使用另一个ftp应用程序)知道ftp服务器上存在’lib1’目录并且我的凭据(用户名和密码)是正确的。 这是我的代码: public class FTPClient { public string UserName { get; set; } public string Password { get; set; } public string IpAddress { get; set; } public int Port { get; set; } public FTPClient(string _userName, string _password, string _address, int _port) { UserName […]

FtpWebRequest下载文件

以下代码旨在通过FTP检索文件。 但是,我收到了一个错误。 serverPath = “ftp://xxxx/tmp/myfile.txt”; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverPath); request.KeepAlive = true; request.UsePassive = true; request.UseBinary = true; request.Method = WebRequestMethods.Ftp.DownloadFile; request.Credentials = new NetworkCredential(username, password); // Read the file from the server & write to destination using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) // Error here using (Stream responseStream = response.GetResponseStream()) using (StreamReader reader = new […]