FtpWebRequest在文件名中保存带有编码字符的下载文件 [英] FtpWebRequest saving downloaded file with encoded characters in the file name
问题描述
我有一个关于通过FtpWebRequest下载文件的问题。当我下载所需文件时,一切正常,但如果文件名中有空格,文件名将以%20替换实际空格保存(例如 remote / folder / my file.whatever local\folder\my %20 file.whatever 。如果我列出文件所在的文件,则不包含结果中的编码字符。
我知道可能有些东西很傻/小我错过了,但我正拉着(剩下的东西)我的头发了!
除非创建一个辅助类来查找/替换新下载文件中的违规字符,否则在保存文件时我可以做些什么来解决这个问题?
我的代码如下:
Hi,
I have a question regarding file downloading via FtpWebRequest. All works well when I download the needed files, but if the filename has a space in it, the filename is saved with %20 replacing the actual space (eg. remote/folder/my file.whatever becomes local\folder\my%20file.whatever. If I do a file listing of where the file is, it does not contain the encoded character in the result.
I know there is probably something silly/small that I am missing, but I'm pulling (what little is left of) my hair out!
Barring creating a helper class to find/replace the offending characters in the newly downloaded file, is there something that I can do when the file is saved that will resolve this issue?
My code is something as follows:
FtpWebRequest request = FtpWebRequest.Create(myUriWithFileName) as FtpWebRequest;
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(username, password); // credentials as necessary...
request.UsePassive = false;//or true as is necessary
request.UseBinary = true;
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
{
StreamToFile(responseStream, @"c:\Temp\my file.whatever"); // StreamToFile is just a helper to write from one stream to another...
}
提前谢谢!
Thanks in advance!
推荐答案
谢谢你们所有人,如上所述,我结束了使用第三方组件来完成我需要它做的事情。
干杯!
Thanks one and all, as noted above I ended up using a third party component to do what I needed it to do.
Cheers!
这篇关于FtpWebRequest在文件名中保存带有编码字符的下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!