0
WinSCP를 사용하여 SFTP에서 파일을 다운로드하고 있는데 이것은 내 코드입니다.WinSCP C#에서 오류 코드를 확인하는 방법
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();
}
어떻게 오류를 확인할 수 있습니까? Here 그들은 오류 코드를 정의했으나 암호가 잘못되었거나 파일이 종료되지 않았는지 확인하기 위해 어떻게 코드에 구현할 수 있습니까?
try/catch 블록을 사용하고 https://sshnet.codeplex.com/을 시도하십시오. – Mate
sshnet은 WinScp를 사용하고있는 다른 라이브러리입니다.이 태그는 try/catch하지만 오류가 발생하지 않습니다 내 SFTPClient.cs입니다. 그 집에 캐치하려고하지만 집에서 대신이 클래스가 호출 될 때 잡으려고 – Coder
미안하지만, 혼란 스러웠습니다. 이 코드는 다른 질문과 동일합니다. http://stackoverflow.com/questions/26227676/download-file-using-sshnet – Mate