FtpWebRequest.Method 속성

정의

FTP 서버에 보낼 명령을 가져오거나 설정합니다.

public:
 virtual property System::String ^ Method { System::String ^ get(); void set(System::String ^ value); };
public override string Method { get; set; }
member this.Method : string with get, set
Public Overrides Property Method As String

속성 값

서버에 보낼 FTP 명령이 들어 있는 String 값입니다. 기본값은 DownloadFile입니다.

예외

이미 진행 중인 요청의 이 속성에 새 값이 지정된 경우

메서드가 잘못된 경우

또는

메서드가 지원되지 않습니다.

또는

여러 메서드가 지정된 경우

예제

다음 코드 예제에서는이 속성을 설정 합니다 DeleteFile.

static bool DeleteFileOnServer( Uri^ serverUri )
{
   // The serverUri parameter should use the ftp:// scheme.
   // It contains the name of the server file that is to be deleted.
   // Example: ftp://contoso.com/someFile.txt.
   // 
   if ( serverUri->Scheme != Uri::UriSchemeFtp )
   {
      return false;
   }

   // Get the object used to communicate with the server.
   FtpWebRequest^ request = dynamic_cast<FtpWebRequest^>(WebRequest::Create( serverUri ));
   request->Method = WebRequestMethods::Ftp::DeleteFile;
   FtpWebResponse^ response = dynamic_cast<FtpWebResponse^>(request->GetResponse());
   Console::WriteLine( "Delete status: {0}", response->StatusDescription );
   response->Close();
   return true;
}
public static bool DeleteFileOnServer(Uri serverUri)
{
    // The serverUri parameter should use the ftp:// scheme.
    // It contains the name of the server file that is to be deleted.
    // Example: ftp://contoso.com/someFile.txt.
    //

    if (serverUri.Scheme != Uri.UriSchemeFtp)
    {
        return false;
    }
    // Get the object used to communicate with the server.
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
    request.Method = WebRequestMethods.Ftp.DeleteFile;

    FtpWebResponse response = (FtpWebResponse) request.GetResponse();
    Console.WriteLine("Delete status: {0}",response.StatusDescription);
    response.Close();
    return true;
}

설명

속성은 Method 서버로 전송되는 명령을 결정합니다. 클래스의 Method 공용 필드 멤버에 정의된 문자열을 사용하여 를 WebRequestMethods.Ftp 설정합니다. 클래스에 정의된 문자열은 속성에 WebRequestMethods.Ftp 대해 지원되는 유일한 옵션 Method 입니다. Method 속성을 다른 값으로 설정하면 예외가 발생합니다ArgumentException.

로 설정할 Method 때 메서드를 UploadFile호출 GetRequestStream 하기 전에 이 작업을 수행해야 합니다. 이러한 멤버를 올바른 순서로 호출하지 못하면 요청 스트림을 ProtocolViolationException 가져올 때 예외가 발생합니다.

개체에 제공된 자격 증명에는 FtpWebRequest 지정된 메서드를 수행할 수 있는 권한이 있어야 합니다. 그렇지 않으면 FTP 명령이 실패합니다.

명령의 성공 또는 실패를 확인하려면 및 StatusDescription 속성을 검사StatusCode.

적용 대상

추가 정보