Can't delete file right after creating them
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 4.4k
- Fork
- 993
- Merge medio
- 9g 21h
- PR unite (30g)
- 1
Descrizione
I am wondering if this is an issue or my process flaw. I am not be able to delete a file that just created. But, on WinSCP, I am able to delete them manually.
There is a case where the file got locked and I can't delete them because it says that "Permission Denied" and I can't delete them as SFTP user or OS (windows) user. I did checked that the file is owned by Administrator.
Here is the code that I use to produce the problem.
private static void uploadZip(string fTPAddress, string ftpPath, string fTPUsername, string fTPPassword, string zipFilePath, string zipFileName) {
// Build username/password
var passwordAuth = new PasswordAuthenticationMethod(fTPUsername, fTPPassword);
// Build connection
var connectionInfo = new ConnectionInfo(fTPAddress, fTPUsername, passwordAuth);
using (var client = new SftpClient(connectionInfo)) {
Console.WriteLine("Connecting " + fTPAddress + "... ");
client.Connect();
Console.WriteLine(client.IsConnected ? "Connected!" : "Disconnected.");
// Upload file
try {
Console.WriteLine("Creating new path + file...");
client.Create(ftpPath + zipFileName);
Console.WriteLine("Created!");
if (client.Exists(ftpPath + zipFileName)) {
Console.WriteLine(ftpPath + zipFileName + " Exists!");
Console.WriteLine("Deleting " + ftpPath + zipFileName + "... ");
client.Delete(ftpPath + zipFileName);
Console.WriteLine("Deleted");
} else {
Console.WriteLine("Uploading file...");
using (FileStream stream = File.Open(zipFilePath, FileMode.Open)) {
client.UploadFile(stream, ftpPath + zipFileName);
}
Console.WriteLine("Uploaded!");
}
} catch (Exception e) {
Console.WriteLine("-- Something wrong on execution: " + e.Message);
Console.WriteLine(e.StackTrace);
} finally {
Console.WriteLine("Disconnecting... ");
client.Disconnect();
Console.WriteLine(client.IsConnected ? "Connected!" : "Disconnected.");
Console.WriteLine("Deleting " + zipFilePath + "...");
File.Delete(zipFilePath);
Console.WriteLine(zipFilePath + " Deleted...");
}
}
}
The output:
C:\Users\btobias>C:\WorkingCopies\PCCDBAssembly\PCCDB.Docs.Run\bin\Dev\PCCDB.Docs.Run.exe
( 0 milliseconds) Type found: PCCDB.PCC.Library.LibraryPatronDump
( 0 milliseconds) Method found: LibraryPatronDumpExe
( 1 milliseconds) Parameter 0: ftpAddress (System.String): ftp.test.com
( 1 milliseconds) Parameter 1: ftpPath (System.String): /alma/test/
( 1 milliseconds) Parameter 2: ftpUsername (System.String): XXXXX
( 2 milliseconds) Parameter 3: ftpPassword (System.String): XXXXXXXXXXXXXX
( 2 milliseconds) Parameter 4: syncPersonnelIncluded (System.String): Y
( 3 milliseconds) Executing...
( 9292 milliseconds) Connecting ftp.pcci.edu...
( 9528 milliseconds) Connected!
( 9528 milliseconds) Creating new path + file...
( 9539 milliseconds) Created!
( 9546 milliseconds) /alma/test/PatronDump2.zip Exists!
( 9546 milliseconds) Deleting /alma/test/PatronDump2.zip...
( 9553 milliseconds) -- Something wrong on execution: Permission denied
( 9555 milliseconds) at Renci.SshNet.Sftp.SftpSession.RequestRemove(String path)
at PCCDB.PCC.Library.LibraryPatronDump.uploadZip(String fTPAddress, String ftpPath, String fTPUsername, String fTPPassword, String zipFilePath, String zipFileName) in C:\WorkingCopies\PCCDBAssembly\PCCDB.Docs\PCC\Library\LibraryPatronDump.cs:line 94
( 9556 milliseconds) Disconnecting...
( 9607 milliseconds) Disconnected.
( 9607 milliseconds) Deleting C:\Temp\PatronDump2.zip...
( 9609 milliseconds) C:\Temp\PatronDump2.zip Deleted...
( 9609 milliseconds) Finished...
( 9610 milliseconds)
Press any key...
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Start with the reported SftpClient.Create and client.Delete sequence, then inspect the SftpSession.RequestRemove call shown in the stack trace. Reproduce the permission-denied result and compare it with the server and Windows ownership details; done means establishing whether SSH.NET or the server permissions are responsible, with a focused regression test only if the library is at fault.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- networking
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100