0

WinSCP を使用して SFTP からファイルをダウンロードしています。これが私のコードです。

SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Sftp,
    HostName = ConfigurationManager.AppSettings["SFTPDomain"],
    UserName = ConfigurationManager.AppSettings["SFTPUser"],
    Password = ConfigurationManager.AppSettings["SFTPPass"],
    GiveUpSecurityAndAcceptAnySshHostKey = true,
    PortNumber = 22
};

using (Session session = new Session())
{
    //Attempts to connect to your SFtp site
    session.Open(sessionOptions);

    //Get SFtp File
    TransferOptions transferOptions = new TransferOptions();
    transferOptions.TransferMode = TransferMode.Binary; //The Transfer Mode - Automatic, Binary, or Ascii 
    transferOptions.FilePermissions = null;  //Permissions applied to remote files; 
    transferOptions.PreserveTimestamp = false;  //Set last write time of destination file 
    //to that of source file - basically change the timestamp to match destination and source files.    
    transferOptions.ResumeSupport.State = TransferResumeSupportState.Off;
    //SFTP File Path
    Sftpserver = ConfigurationManager.AppSettings["SFTPFileName"].ToString();
    //Delete File if Exist
    if (System.IO.File.Exists(FilePath))
    {
        System.IO.File.Delete(FilePath);
    }
    //the parameter list is: remote Path, Local Path with filename 
    TransferOperationResult transferOperationResult = session.GetFiles("p", FilePath, false, transferOptions);
    //Throw on any error 
    transferOperationResult.Check();
}

エラーを確認するにはどうすればよいですか。ここでエラーコードを定義しましたが、コードに実装して、パスワードが間違っているかファイルが存在しないかどうかを確認するにはどうすればよいですか。

4

1 に答える 1

0

WinSCP .NET アセンブリ API はエラー コードを提供しません。WinSCP は、FTP、SFTP、SCP、WebDAV など、さまざまなプロトコルをサポートしていることに注意してください。そのため、チェックするコードのセットは 1 つもありません。各プロトコルには異なるコードがあります。さらに、SFTP/SCP エラー セットとは異なる、SSH プロトコルからのエラー (間違ったパスワードの場合) があります。次に、ローカル ファイルにアクセスするときのエラーの WinAPI コードのセットが異なります。

于 2014-10-07T07:14:03.710 に答える