System Error Code 5 Redux

Advertisement

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

System Error Code 5 Redux

As described elsewhere, I have been getting "Access Denied" with my nightly script for some time now. My script syncs my server running phpBB to my desktop. Typically, I get the error when attempting to delete a now empty directory because of an upgrade to phpBB. I have been manually deleting the directory, but this latest upgrade apparently remove a directory tree on the server, and so the error repeats on the next empty subdir, of which there appear to be many. So it's time to solve the problem.

I have followed the debugging guide described here, including the initial read/write test, but the error persists.

Relevant scripts and logs attached.
-Dan

Edit: example.bat was interactively executed in a CMD session, in directory I:\vps116136. I can, from this same user session, manually delete directories that report "Access Denied" when running the script.
  • example.out.txt (2.25 KB, Private file)
Description: (.txt appended to enable upload)

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
42,424
Location:
Prague, Czechia

Re: System Error Code 5 Redux

Thanks for your detailed report. What is the I: drive? Is it a local drive?

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, use /log=C:\path\to\winscp.log command-line argument. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

Yes, I:\ is a local 1 TB drive. My C:\ is a smaller SSD, and I save it for the OS and programs.
The log file is attached, untouched, so I have marked it private. The script was run with V6.5.3 of WinSCP.

Thanks
Dan
  • example.zip (3.43 MB, Private file)

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
42,424
Location:
Prague, Czechia

Thanks. Few things to test:
  • If you run the synchronization manually from WinSCP scripting console (so that WinSCP does not exit on the error) – can you delete the folder after the error from other application without exiting WinSCP? (to check if WinSCP has the folder locked somehow).

  • Same way, if you re-run the synchronization after the error (from the same WinSCP instance), does it complete or fail the same way on the same folder?

  • Try turning off your antivirus temporarily during the synchronization.

Reply with quote

Advertisement

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

Ah! I see I can get a winscp prompt if I do this:
I:\vps116136>C:\Users\dan\AppData\Local\Programs\WinSCP\WinSCP.com
winscp>
But I'm not sure where to go from there. If I fully qualify the path to WinSCP.exe and supply it with the /script and /log parameters, I get "Unknown command". I will continue to review the documentation...

Reply with quote

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

OK, so I tried the second suggestion first, so as to preserve the folder that WinSCP errors on:
Same way, if you re-run the synchronization after the error (from the same WinSCP instance), does it complete or fail the same way on the same folder?
It fails again, on the same folder. I then tried the first suggestion:
If you run the synchronization manually from WinSCP scripting console (so that WinSCP does not exit on the error) – can you delete the folder after the error from other application without exiting WinSCP? (to check if WinSCP has the folder locked somehow).
I am able to delete the folder using Windows Explorer without issue, while the WinSCP session remains open.

Dan

Reply with quote

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

By the way, it is now failing on a (new) empty directory:
Synchronizing...
Error deleting file 'I:\vps116136\faulkner\59forum\vendor\lusitanian\oauth\src\OAuth\Common\Http\Client'.
System Error.  Code: 5.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
42,424
Location:
Prague, Czechia

Thanks for all the tests.
Does WinSCP fail to delete any (empty) local directory?
So even if you do something trivial like this (in Windows Command prompt)
cd /d %USERPROFILE%\Documents
mkdir folder
cd folder
mkdir empty
"C:\Users\dan\AppData\Local\Programs\WinSCP\WinSCP.com"
And in WinSCP prompt:
open ...
cd /home/faulkner
mkdir folder
cd folder
synchronize local -delete -preservetime
Would it then fail to delete the empty folder?

Reply with quote

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

No, it deletes the folder:
C:\Users\dan>cd Documents

C:\Users\dan\Documents>mkdir folder

C:\Users\dan\Documents>cd folder

C:\Users\dan\Documents\folder>mkdir empty

C:\Users\dan\Documents\folder>"C:\Users\dan\AppData\Local\Programs\WinSCP\WinSCP.com"
winscp> open ...
Opening tunnel...
Searching for host...
Connecting to host...
Authenticating...
Using username "faulkner".
Authenticating with public key "Dan's MVPS" from agent.
Authenticated.
Connecting through tunnel...
Searching for host...
Connecting to host...
Authenticating...
Using username "faulkner".
Authenticating with public key "Dan's MVPS" from agent.
Authenticated.
Starting the session...
Session started.
Active session: [1] faulkner@127.0.0.1
winscp> cd /home/faulkner
/home/faulkner
winscp> mkdir folder
winscp> cd folder
/home/faulkner/folder
winscp> synchronize local -delete -preservetime
Using configured transfer settings different from factory defaults.
Comparing...
Local 'C:\Users\dan\Documents\folder' <= Remote '/home/faulkner/folder'
Synchronizing...
Local 'C:\Users\dan\Documents\folder' <= Remote '/home/faulkner/folder'
'C:\Users\dan\Documents\folder\empty' deleted
winscp>
Could it have something to do with the depth of the subfolder it's trying to delete? In my case, it has a depth of 11...
I will repeat this test, naming subdirs alphabetically up through "M".

Dan

Reply with quote

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

Well, that's not it:

...
winscp> pwd
/home/faulkner/folder/a/b/c/d/e/f/g/h/i/j/k/l
winscp> cd ../../../../../../../..
/home/faulkner/folder/a/b/c/d
winscp> cd ../../../..
/home/faulkner/folder
winscp> synchronize local -delete -preservetime
Comparing...
Local 'C:\Users\dan\Documents\folder\a\b\c\d\e\f\g\h\i\j\k\l' <= Remote '/home/faulkner/folder/a/b/c/d/e/f/g/h/i/j/k/l'
Synchronizing...
Local 'C:\Users\dan\Documents\folder\a\b\c\d\e\f\g\h\i\j\k\l' <= Remote '/home/faulkner/folder/a/b/c/d/e/f/g/h/i/j/k/l'
'C:\Users\dan\Documents\folder\a\b\c\d\e\f\g\h\i\j\k\l\m' deleted
winscp>

Reply with quote

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

...and just for kicks - thinking that perhaps, the length of the string had something to do with it, I replicated locally in ..\folder the subdir that the script would not delete, as well as remotely in ../folder (excepting the target for deletion, the local "\Client" subdir):

...
Synchronizing...
Local 'c:\Users\dan\Documents\folder\59forum\vendor\lusitanian\oauth\src\OAuth\Common\Http' <= Remote '/home/faulkner/folder/59forum/vendor/lusitanian/oauth/src/OAuth/Common/Http'
'c:\Users\dan\Documents\folder\59forum\vendor\lusitanian\oauth\src\OAuth\Common\Http\Client' deleted

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
42,424
Location:
Prague, Czechia

Again, thanks for all the thorough tests.

Just to make sure I understand it correctly:
WinSCP fails to delete a particular local empty folder. Even after repeatedly running the same synchronization – still fails on the same folder. You then delete the folder manually (in Windows Explorer), recreate the same folder – and then WinSCP is able to delete it. Is my understanding correct?

Also when the script is not able to delete the folder, is WinSCP GUI able to delete it? Both manually when selecting it in file panel and automatically by running the synchronization in GUI.

Reply with quote

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

Just to make sure I understand it correctly:
WinSCP fails to delete a particular local empty folder. Even after repeatedly running the same synchronization – still fails on the same folder.
This is correct.
You then delete the folder manually (in Windows Explorer), recreate the same folder – and then WinSCP is able to delete it. Is my understanding correct?
I haven't actually tried this experiment. What I did was create an entirely different path, per your suggestion, and confirm that with the folder removed from the server, WinSCP would delete on the desktop with sync. I have confirmed that if WinSCP fails to delete an empty folder on the desktop, I can remove it with Windows Explorer, subsequent to the script running, or manually running the GUI and leaving it open after the failure.
Also when the script is not able to delete the folder, is WinSCP GUI able to delete it? Both manually when selecting it in file panel and automatically by running the synchronization in GUI.
I will try this. Should it fail, I will delete and recreate with Windows Explorer, and repeat the experiment in the WinSCP GUI.
I'll report back with my findings.

Reply with quote

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

I have run C:\...\WinSCP.com, open... , set the local and remote working directories, followed by the synch. Again, I get this error:

Error deleting file 'I:\vps116136\faulkner\59forum\vendor\lusitanian\oauth\src\OAuth\Common\Http\Client'.
System Error.  Code: 5.
Access is denied
I then lcd down to ...\Http, but: What command can I give in the WinSCP console, to locally rmdir? "help" doesn't indicate that there is one.

At any rate, I will remove the subdir and recreate it with Windows Explorer, and try again.

Reply with quote

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

The plot thickens...
...\Http contains three subfolders - \Client, \Exception, and \Uri. At the outset of the latest experiment, Client was empty, the other two contained files.
When I ran synchronize in the console, it failed to remove Client. In Windows, I deleted it and recreated it; then, ran synchronize again:
Synchronizing...
Error deleting file 'I:\vps116136\faulkner\59forum\vendor\lusitanian\oauth\src\OAuth\Common\Http\Exception'.
System Error.  Code: 5.
Access is denied
Now it fails on Exception, which by the way, has been emptied of its contents by WinSCP. Note that Client - which I first deleted, then recreated - remains. I'll also note that Client has today's date (of course), but that Exception and Uri are dated July 24, 2024. Presumably, the original Client folder had the same 2024 date.

Reply with quote

Advertisement

martin
Site Admin
martin avatar

The order in which folders are being synchronized is not necessarily deterministic. So please delete and recreate Exception too (and possibly later also Uri) and see what happens.

Reply with quote

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

Using the console command to synchronize, WinSCP emptied Uri of its files before complaining that it could not delete the folder itself, just as with Client and Exception. Now all three subfolders of Http were empty of files. As with Client and Exception, I used Windows Explorer to delete and recreate Uri. Repeating the console command, WinSCP now deleted all three subfolders before complaining that it could not delete the parent folder Http.

I will add: WinSCP initially created a copy of the V3.3.5 distribution of phpBB on my server to my local I: drive, including I:\vps116136\faulkner\59forum\vendor\lusitanian with all of its subfolders and files. At some point in development, phpBB removed lusitanian from the distribution, and I encountered these errors when upgrading to V3.3.15. But the directories that WinSCP is now attempting to delete, were initially created by WinSCP.

Reply with quote

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

Here's an update.

Having gone over a week now without a complete backup, I decided to move I:\vps116136\faulkner\59forum, along with all of its subfolders and files, up one level to I:vps115136\59forum. I then reran the script, re-backing up my entire site. It did so, and ran to completion without error. N.B.: Server-side, the ../lusitanian subfolder was gone as a result of the phpBB upgrade from 3.3.5 to 3.3.15.

As a further test, I then copied the 3.3.5 distribution lusitanian folder up into the vendor subfolder on the server. I then reran the script, and it updated my local backup to include the lusitanian folder.

I then deleted lusitanian server side, and reran the script. WinSCP removed the lusitanian subfolder and all of its files and subfolders successfully to completion.

I will keep the "saved-off" backup, and move it back into position (after moving off the complete, successful backup), if there is any interest in continuing to pursue this issue affecting WinSCP. But I am at a loss as to what is causing it, and I am concerned that it will happen again. Please advise.

Reply with quote

Advertisement

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

Just to note - I saved off the new phpBB directory tree, moved the old back in place, and reran the script:
< 2025-10-13 12:04:02.106 Script: Error deleting file 'I:\vps116136\faulkner\59forum\vendor\lusitanian\oauth\src\OAuth\Common\Http'.
< 2025-10-13 12:04:02.106 System Error.  Code: 5.
< 2025-10-13 12:04:02.106 Access is denied
As I said at the beginning of this thread, this is not the first time this error has occurred - usually, it is because a single directory is purged of files, but the directory itself is not removed. I know that it will happen again. But I will soon be deleting this directory which consistently produces an error, unless there is an interest in pursuing what might be responsible for it.

Dan

Reply with quote

martin
Site Admin
martin avatar

Can you dump permissions of the folder that cannot be deleted using icacls I:\vps116136\faulkner\...? And then again after you recreate it (when it can be deleted)?

Reply with quote

shortmort37
Donor
Joined:
Posts:
30
Location:
Philadelphia

NEW INFORMATION!
I did as you asked, and ran the icacls command on ..\Http:
Http
D:NO_ACCESS_CONTROL
And got the same result, after its removal and recreation with CMD:
Http
D:NO_ACCESS_CONTROL
BUT! after I first ran icacls, I attempted to remove the empty Http subfolder with CMD - and got "Access Denied"! Yet, I was able to delete the subfolder with Windows Explorer!

I was able to rmdir with CMD, the Http subdir I had mkdir with CMD. While I have destroyed this test case, I am sure one of the other subfolders in the lusitanian folder will present with the same "Access Denied" error from WinSCP, as well as CMD. I am rerunning the script now.

What accounts for the fact that I can delete these folders - originally created with a WinSCP script - with Windows Explorer, but not CMD?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
42,424
Location:
Prague, Czechia

I seems that the whole directory tree has some broken permissions (and new folders inherit that). Windows File Explorer is able to silently bypass permissions issues, when it is used by a user that has Admin privileges (I assume that's your case).
You can try to fix the permissions by:
icacls I:\vps116136\faulkner /reset /T

Reply with quote

Advertisement

You can post new topics in this forum