C#에서 FtpWebRequest
클래스로 작업 할 때 문제가 발생했습니다.FtpWebRequest는 올바른 암호를 사용하여 이전 연결 성공 후 잘못된 암호를 무시합니다.
처음으로 올바른 자격 증명을 사용하여 파일을 FTP 서버에 업로드하려고 시도한 다음 두 번째로 잘못된 자격 증명 (사용자 이름은 동일하지만 잘못된 암호)을 던지면 아무 예외도 발생하지 않으며 파일은 여전히 유지됩니다 FTP 서버에 업로드되었습니다. 여기
using System;
using System.Net;
internal class Program
{
private static void Main(string[] args)
{
var uri = new Uri("ftp://ftp.dlptest.com/TestFile.txt");
var method = WebRequestMethods.Ftp.UploadFile;
//Here I'm uploading the test file using correct credentials
var correctCredentials =
new NetworkCredential("[email protected]", "fwRhzAnR1vgig8s");
DoFtpRequest(uri, correctCredentials, method);
//Here I'm uploading the test file using wrong credentials.
//I expect some exception to be thrown and the file not being
//uploaded to the server, neither is the case.
var wrongCredentials =
new NetworkCredential("[email protected]", "WRONG_PASWORD");
DoFtpRequest(uri, wrongCredentials, method);
}
public static FtpWebResponse DoFtpRequest(
Uri uri, NetworkCredential credentials, string method)
{
var request = (FtpWebRequest)WebRequest.Create(uri);
request.Credentials = credentials;
request.Method = method;
return (FtpWebResponse)request.GetResponse();
}
}
내가 여기에이 코드를 테스트하는 데 사용할 수있는 https://dlptest.com/ftp-test/을 발견 공개 FTP 서버 ftp://ftp.dlptest.com/
를 사용하고 다음 코드를 고려하시기 바랍니다.
처음부터 알 수 있듯이 올바른 자격 증명을 사용하여 파일을 업로드 한 다음 잘못된 자격 증명 (동일한 사용자 이름을 사용하지만 암호는 변경)을 사용하여 파일을 업로드하려고합니다. 그러나 파일은 여전히 서버에 업로드됩니다. 잘못된 자격 증명을 먼저 사용하려고하면 예외가 발생하고 모든 것이 예상대로 작동합니다.
무슨 일이 일어나고 있는지 아십니까? 이것은 프레임 워크의 버그입니까? 이 문제를 해결할 수있는 옵션은 무엇입니까? 지금 작업하고있는 프로그램에 문제가 발생했기 때문입니다.