我尝试下载文件,但所有具有特殊字符的文件都无法识别。可以下载其他文件,文件名为asdf#[email protected] /cdn-cgi/l/email-protection
无法下载。
Error:
远程服务器返回错误:(550) 文件不可用(例如,未找到文件、无法访问)。
在本地,创建了名称正确的文件,但它是空的。 JPG 文件也会发生同样的情况#
文件名里面。我怎样才能让他们被认可呢?
//Download the file from remote path on FTP to local path
private static void Download(string remotePath, string localPath)
{
FtpWebRequest reqFTP;
try
{
reqFTP = GetWebRequest(WebRequestMethods.Ftp.DownloadFile, remotePath);
FileStream outputStream = new FileStream(localPath, FileMode.Create);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
response.Close();
Console.WriteLine("File Download: ", remotePath + " is downloaded completely");
logWriter.WriteLog("File Download: ", remotePath + " is downloaded completely, status " + response.StatusDescription);
}
catch (Exception ex)
{
logWriter.WriteLog("File Download: ", "Cannot download file from " + remotePath + " to " + localPath + "\n" + " Erro Message: " + ex.Message);
}
}//End Download
//Web request for FTP
static public FtpWebRequest GetWebRequest(string method, string uri)
{
Uri serverUri = new Uri(uri);
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return null;
}
try
{
var reqFTP = (FtpWebRequest)FtpWebRequest.Create(serverUri);
reqFTP.Method = method;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(userId, password);
reqFTP.Proxy = null;
reqFTP.KeepAlive = false;
reqFTP.UsePassive = false;
return reqFTP;
}
catch(Exception ex)
{
logWriter.WriteLog("Get Web Request: ","Cannot connect to " + uri + "\n" + "Error: " + ex.Message);
return null;
}
}