FTP 서버에서 파일을 다운로드하는 코드는 여기에 있습니다. 대소 문자를 구별합니다. 대소 문자를 구분하여 다운로드 할 수 있도록 도와주세요.File in case with encencitive match C#
예 : "6Gt6hh.xml"을 다운로드하려고하지만 기존 파일이 ftp 인 경우 서버가 "6GT6hh.Xml"입니다. 내 코드로 다운로드하지 않으면 도움이 될 수 있습니다.
private void Download(string file, ServerCredentials FtpCdrl, string DayOfYear, string dest, string ab)
{
try
{
string uri = "ftp://" + FtpCdrl.Host + "/" + FtpCdrl.DirPath.Replace("\\", "/") + "/" + DayOfYear + "/" + file;
Uri serverUri = new Uri(uri);
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return;
}
if (!Directory.Exists(dest))
Directory.CreateDirectory(dest);
if (!Directory.Exists(dest + "\\" + ab))
Directory.CreateDirectory(dest + "\\" + ab);
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + FtpCdrl.Host + "/" + FtpCdrl.DirPath.Replace("\\", "/") + "/" + DayOfYear + "/" + file));
reqFTP.Credentials = new NetworkCredential(FtpCdrl.UID, FtpCdrl.Pwd);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = null;
reqFTP.UsePassive = false;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream responseStream = response.GetResponseStream();
FileStream writeStream = new FileStream(dest + "\\" + ab + "\\" + file, FileMode.Create);
int Length = 2048;
Byte[] buffer = new Byte[Length];
int bytesRead = responseStream.Read(buffer, 0, Length);
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = responseStream.Read(buffer, 0, Length);
}
status("File Downloaded Successfully: .\\" + ab + "\\" + file, Color.Green);
writeStream.Close();
response.Close();
failed = 0;
}
catch (WebException wEx)
{
failed++;
status("[Download Error]" + wEx.Message, Color.Red);
if (failed < 3)
Download(file, FtpCdrl, DayOfYear, dest, ab);
}
catch (Exception ex)
{
status("[Download Error]" + ex.Message, Color.Red);
}
}
public class ServerCredentials
{
public string Host, UID, Pwd, DirPath;
public int Pst;
public string Mail;
public string facility;
public string Batchextn;
public ServerCredentials(string _Host1, string _DirPath1, string _Uid1, string _Pwd1, string _Mail, int _Pst1, string _facility, string _batchextn)
{
Host = _Host1;
UID = _Uid1;
Pwd = _Pwd1;
DirPath = _DirPath1;
Pst = _Pst1;
Mail = _Mail;
facility = _facility;
Batchextn = _batchextn;
}
}
public List<ServerCredentials> Svr = new List<ServerCredentials>();
이 유용 ->를 나열 -> 그것을 일치 ->을 다운로드 -> 즉 하나의 선택. 디렉토리가 대소 문자와 일치하지 않으면 어떻게 디렉토리 목록에 액세스 할 수 있습니까? 이제는 이와 같은 모든 디렉토리를 처리하는 데 오랜 시간이 걸립니다. 어쨌든 당신의 도움에 감사드립니다 :). – Civa