I am working on FTP client for internal usage for deployments. I have started out with WinSCP scripts, everything seems to be working fine, except one operation (deleting large(many files) directory containing files and sub-directories). I know that my targeted FTP server does not support 'recursive directory removal', however it is possible to achieve desired operation by doing recursion on client side (list all files/dirs and delete everything one by one).
WinSCP script line that fails:
Lost connection. Disconnected from server Error deleting file '/path/to/large_directory/InnerDir/InnerDir2/dir'. Error deleting file '/path/to/large_directory/InnerDir/InnerDir2'. Error deleting file '/path/to/large_directory/InnerDir'. Error deleting file '/path/to/large_directory'. Session 'email@example.com' closed. No session.
After not being able to find solution on WinSCP script, decided to write on my own deployment application using C# and open source library 'System.Net.FtpClient'. However soon enough faced the same issue 'recursive large directory removal' fails. Except this time had more information about error:
Disposing FtpClient object... Disposing FtpSocketStream... System.IO.IOException: Unable to read data from the transport connection: An attempt was made to access a socket in a way forbidden by its access permissions. ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) --- End of inner exception stack trace ---
Challenge: error occurrence is unpredictable, in a sense that given directory which contains only few inner directories or files may succeed or fail, but given larger case it is almost guaranteed to fail. This applies to WinSCP and C# application. So, in theory this is possible solution - keep repeating the script until directory is completely removed, but doing that brings another challenges (manual re-connection is one of them).
While trying many different things, found out that completely disabling Windows 10 firewall did the trick. Thus allowed C# app and WinSCP script run flawlessly.
I need help with setting up firewall correctly, but no matter what I do the problem still persists, except if firewall is completely disabled. I have even created inbound / outbound rules, which should apply for all profiles, all local/remote ip addresses, ports, application/services... still no desired results.