我创建了一个小型 FTP 程序,仅供我自己使用,因此登录详细信息 + 文件路径是硬编码的。
我有一个按钮,可以启动两个 txt 文件的下载过程 - 这些文件的内容被放入两个不同的文本框中。
txt 文件使用 UTF-8 编码,如下所示:
line1
line2
line3
etc.
我已将这两个文件放在两个不同的服务器上(每个服务器上有两个文件)。在服务器 1 上,两个文件均已下载并正确显示在文本框中,如下所示:
line1
line2
line3
etc.
在服务器 2 上,两个文件均已下载并显示在文本框中,如下所示:
line1line2line3etc.
我真的不明白为什么 - 我不编辑了软件(下载过程)也没有编辑文件,当然,由于服务器的变化,我只编辑了硬编码的文件路径。
这就是我下载其中一个文件的方式(另一个文件的方式相同,只是名称不同):
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(folder + artistsFileNameTxt);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(login, pass);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
tbxArtists.Text = reader.ReadToEnd();
reader.Close();
response.Close();
有帮助吗?
I have created a small FTP program, it's just for my own use, so login details + the file paths are hard coded.
I have a button which starts the downloading process of two txt files - the contents of these are put into two different textboxes.
The txt files are encoded with UTF-8, and look like this:
line1
line2
line3
etc.
I have placed these two files on two different servers (two files on each server). On server 1, both files are downloaded and shown in the textboxes correctly, like this:
line1
line2
line3
etc.
On server 2, both files are downloaded and shown in the textboxes like this:
line1line2line3etc.
I really don't understand why - I have not edited the software (the downloading process) nor the files, I have only edited the hard coded file paths of course, because of the change of server.
This is how I download one of the files (the other file is the same way, just with different names):
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(folder + artistsFileNameTxt);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(login, pass);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
tbxArtists.Text = reader.ReadToEnd();
reader.Close();
response.Close();
Any help?
发布评论
评论(3)
尝试
默认值为 true...仅当您确定正在处理文本文件时才执行此操作。
FTP 协议具有此“内置”功能来处理有关 NewLine 的系统差异...
顺便说一句,通过 FTP 上传时也必须正确设置此设置,否则可能会变得混乱...
http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.usebinary.aspx
http://www.rhinosoft.com/newsletter/NewsL2008-03-18.asp
try
the default is true... do this ONLY when you are SURE that you are dealing with a text file.
FTP protocol has this "built-in" to deal with system-differences regardings NewLine...
BTW you must set this setting correctly when uploading via FTP too otherwise it can get messy...
http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.usebinary.aspx
http://www.rhinosoft.com/newsletter/NewsL2008-03-18.asp
我的猜测是第一个服务器是Windows,而第二个服务器是Linux。
Windows 新行: \r\n
Linux 新行: \n
在 Windows 中无法正确显示
My guess is that the first server is windows, whereas the second one is linux.
Windows new line: \r\n
Linux new line: \n
is not displayed correctly in windows
尝试
try