sshnet / sshnet/SSH.NET

Can't delete file right after creating them

Offen
#394 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
C#
Sterne
4.4k
Forks
993
Ø Merge
9 T. 21 Std.
Gemergte PRs (30 T.)
1

Beschreibung

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...

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der gemeldeten Sequenz aus SftpClient.Create und client.Delete und untersuche anschließend den im Stacktrace angezeigten Aufruf SftpSession.RequestRemove. Reproduziere das Ergebnis „Berechtigung verweigert“ und vergleiche es mit den Details zu Server und Windows-Besitz; abgeschlossen ist die Untersuchung, wenn festgestellt wurde, ob SSH.NET oder die Serverberechtigungen verantwortlich sind, mit einem fokussierten Regressionstest nur dann, wenn die Bibliothek die Ursache ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.