는 오류
프로세스가 파일을 액세스 할 수 없습니다 제거하는 방법을 말해 줄 수 내 코드
if (!File.Exists(FlagFilePath)) { Debug.WriteLine("Trying to download sales data file "); SessionOptions sessionOptions = new SessionOptions { Protocol = Protocol.Sftp, HostName = ConfigurationManager.AppSettings["SFTPDomain"], UserName = ConfigurationManager.AppSettings["SFTPUser"], Password = ConfigurationManager.AppSettings["SFTPPass"], PortNumber = Convert.ToInt32(ConfigurationManager.AppSettings["SFTPPortNumber"]), GiveUpSecurityAndAcceptAnySshHostKey = true, }; 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 Sftp_RemotePath = 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(Sftp_RemotePath, FilePath , false, transferOptions); //Throw on any error transferOperationResult.Check(); Debug.WriteLine("Downloaded fresh sales data file!"); } }
MVC를 사용하고 있으며이 클래스에 액세스하는 두 개의 컨트롤러가 있습니다. 나는 한 번에 컨트롤러를 하나를 실행하면 다음 그것을 잘 작동하지만 다음 함께 두 컨트롤러를 실행할 때 컨트롤러 중 하나에서이 오류를 얻을 :이 줄 끝에서이 오류를 얻고있다
WinSCP.SessionRemoteException: Can't create file 'D:\TESTING\SFTP\Data.csv'. ---> WinSCP.SessionRemoteException: System Error. Code: 32. The process cannot access the file because it is being used by another process --- End of inner exception stack trace --- at WinSCP.OperationResultBase.Check() at JetStarAPI.Models.SFTPClient.DownloadFile(String FilePath) in D:\TESTING\SFTP\Models\SFTPClient.cs:line 65}
transferOperationResult.Check();
여기
TransferOperationResult transferOperationResult = session.GetFiles(Sftp_RemotePath, FilePath+Path.GetRandomFileName() , false, transferOptions);
파일의 이름을 변경하는 경우 그것은 잘 작동하고 임의의 파일 이름으로 파일을 저장하지만 난 내 이름을 전달하려는. 어떻게 해결할 수 있을까요?
코드 나 다른 응용 프로그램에서 이미 파일을 열지 않았는지 확인해야합니다. 이 오류에 대한 인터넷 검색은 여러 가지 예를 보여줍니다. – Xcelled194
그것은 하나의 요청에 대해 잘 작동하지만,이 오류가 발생하는 것보다 두 컨트롤러를 함께 사용할 때 TransferOperationResult transferOperationResult = session.GetFiles (Sftp_RemotePath, FilePath, false, transferOptions); FilePath를 FilePath + Path.GetRandomFileName()으로 변경하면 작동합니다. – user3754674
예, 하나의 컨트롤러가 이미 파일을 열고 잠그고 다른 하나가이 예외를 발생시키면서 동시에 열려고 시도하기 때문에 * 예. 실제로 파일을 두 번 열려고합니다. GetRandomFileName은 각 컨트롤러가 해당 메서드에서 다른 결과를 받기 때문에 작동하므로 서로 다른 파일에 액세스합니다. – Xcelled194