get -delete removes files and folder, but gives error message that the folder does not exist

Advertisement

mlysons
Donor
Joined:
Posts:
7

get -delete removes files and folder, but gives error message that the folder does not exist

I am using the command:
get -delete "/my-folder/prod/my-download/*" "C:\my-folder\prod\my-download\"
This correctly downloads the first folder and contents from the remote into the local folder. It then correctly deletes that folder and contents from the remote. But, it also gives me an error message saying that the folder does not exist and that it can't be deleted – this stops my script from running.

To be clear – all the files and the folder are deleted from the remote, but WinSCP errors saying the folder does not exist when trying to delete it.

This is a problem, because it means that WinSCP correctly downloads and deletes the first folder and its contents, but then errors and won't download the rest of the folders and contents.

Am I doing something wrong?

Log file entry below. In this example, folder-1 and contents have been correctly downloaded to my local folder. folder-1 and contents have then been correctly deleted from the remote server. However, WinSCP still gives me the error below and the script then fails.

Log File message
. 2021-09-12 12:27:08.926 Deleting file "/my-folder/prod/my-download/folder-1".
> 2021-09-12 12:27:08.926 Type: SSH_FXP_RMDIR, Size: 125, Number: 69135
< 2021-09-12 12:27:09.020 Type: SSH_FXP_STATUS, Size: 141, Number: 69135
< 2021-09-12 12:27:09.020 Status code: 2, Message: 69135, Server: /my-folder/prod/my-download/folder-1, Language: US-ASCII 
. 2021-09-12 12:27:09.020 Asking user:
. 2021-09-12 12:27:09.020 Error deleting file '/my-folder/prod/my-download/folder-1'. ("No such file or directory.
. 2021-09-12 12:27:09.020 Error code: 2
. 2021-09-12 12:27:09.020 Error message from server (US-ASCII): /my-folder/prod/my-download/folder-1")
< 2021-09-12 12:27:09.020 Script: Error deleting file '/my-folder/prod/my-download/folder-1'.
< 2021-09-12 12:27:09.020 Script: No such file or directory.
< 2021-09-12 12:27:09.020 Error code: 2
< 2021-09-12 12:27:09.020 Error message from server (US-ASCII): /my-folder/prod/my-download/folder-1
. 2021-09-12 12:27:09.020 Answer: Abort
. 2021-09-12 12:27:09.020 Script: Failed
. 2021-09-12 12:27:09.020 Script: Exit code: 1
. 2021-09-12 12:27:09.020 Closing connection.
. 2021-09-12 12:27:09.020 Sending special code: 1
. 2021-09-12 12:27:09.192 Session sent command exit status 0

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
36,052
Location:
Prague, Czechia

Re: get -delete removes files and folder, but gives error message that the folder does not exist

Ok, but the error comes from the server. From your post it's not clear if the folder was removed already before and WinSCP incorrectly tries to delete it again (so it's correct that the server returns an error). Or if the server for some reason reports that the folder does not exist, when it actually does, and WinSCP is correctly trying to delete it. Consider posting full log, if you want us to investigate further.

Reply with quote

mlysons
Donor
Joined:
Posts:
7

Re: get -delete removes files and folder, but gives error message that the folder does not exist

Thanks for the response – I am sorry for being unclear, I hope the below text will help?

The end of the log should (hopefully!) make the issue clear.
The file from /network-xfers/prod/Folder-1/ is correctly downloaded.
But when trying to then delete /network-xfers/prod/Folder-1 it fails saying the folder does not exist – clearly it did exist as File-1.xml was within Folder-1 and was downloaded correctly.

I'm wondering if it's my get command that is causing it?
get -delete "/network-xfers/prod/*" "C:\Live\"
If you need a more detailed log please let me know and I will do my best to provide it.
. 2021-09-13 12:04:16.784 Transfer done: '/network-xfers/prod/Folder-1/File-1.xml' => 'C:\Live\Folder-1\File-1.xml' [510790]
. 2021-09-13 12:04:16.784 Deleting file "/network-xfers/prod/Folder-1/File-1.xml".
> 2021-09-13 12:04:16.784 Type: SSH_FXP_REMOVE, Size: 169, Number: 12301
< 2021-09-13 12:04:16.784 Type: SSH_FXP_STATUS, Size: 32, Number: 12036
. 2021-09-13 12:04:16.784 Discarding reserved response
< 2021-09-13 12:04:16.878 Type: SSH_FXP_STATUS, Size: 32, Number: 12301
< 2021-09-13 12:04:16.878 Status code: 0
. 2021-09-13 12:04:16.878 Deleting file "/network-xfers/prod/Folder-1".
> 2021-09-13 12:04:16.878 Type: SSH_FXP_RMDIR, Size: 125, Number: 12559
< 2021-09-13 12:04:16.971 Type: SSH_FXP_STATUS, Size: 141, Number: 12559
< 2021-09-13 12:04:16.971 Status code: 2, Message: 12559, Server: /network-xfers/prod/Folder-1, Language: US-ASCII 
. 2021-09-13 12:04:16.971 Asking user:
. 2021-09-13 12:04:16.971 Error deleting file '/network-xfers/prod/Folder-1'. ("No such file or directory.
. 2021-09-13 12:04:16.971 Error code: 2
. 2021-09-13 12:04:16.971 Error message from server (US-ASCII): /network-xfers/prod/Folder-1")
< 2021-09-13 12:04:16.971 Script: Error deleting file '/network-xfers/prod/Folder-1'.
< 2021-09-13 12:04:16.971 Script: No such file or directory.
< 2021-09-13 12:04:16.971 Error code: 2
< 2021-09-13 12:04:16.971 Error message from server (US-ASCII): /network-xfers/prod/Folder-1
. 2021-09-13 12:04:16.971 Answer: Abort
. 2021-09-13 12:04:16.971 Script: Failed
. 2021-09-13 12:04:16.971 Script: Exit code: 1
. 2021-09-13 12:04:16.971 Closing connection.
. 2021-09-13 12:04:16.971 Sending special code: 1
. 2021-09-13 12:04:17.143 Session sent command exit status 0
. 2021-09-13 12:04:17.143 Main session channel closed
. 2021-09-13 12:04:17.143 All channels closed

Reply with quote

mlysons
Donor
Joined:
Posts:
7

Instead of deleting the remote folders is it possible to issue a get -delete command that will traverse a folder structure and download and delete those files, but NOT delete the remote folders?
e.g.
/my-remote/my-root/folder-1
/my-remote/my-root/folder-2
/my-remote/my-root/folder-3
Can I issue a command to traverse the folders in my-root, download all the files into the same named folder locally, and then delete just the remote files?

Note that the folder structure will change over time and I won't know about that – I need it to traverse all folders in /my-remote/my-root/.

Reply with quote

mlysons
Donor
Joined:
Posts:
7

Additional info to try and meet posting guidelines.

Using WinSCP 5.17.9 (build 10905)

Running using Windows Scheduled Task to run the following batch file:
cd "c:\Program Files (x86)\winscp\"
 
winscp.com /ini=nul  /log="C:\FTP-Download\WinSCP-Log\winscp-Log.txt" /loglevel=1 /logsize=5*10M /script=C:\FTP-Download\Lorenzo\Lorenzo-Download-Script.txt
The script file is as follows:
# This opens the secure connection
# Removed this line for privacy reasons
 
# Use "" to cater for any folders with spaces in the title
get -delete "/network-xfers/prod/my-download/*" "C:\MyDownload\root\"
 
exit
If there are any discrepancies between the script above and the locations in the log file it is due to my editing of the log file – I apologise if there is any confusion caused, but it does not affect the issue itself.
  • WinSCP-Folder-Delete-Issue-Log-File.txt (136.56 KB, Private file)
Description: File edits including removing sensitive information (keys etc) and altering file/folder names (as they are also sensitive). Where I have edited file/folder names I have ensured they match the format of the original names e.g. they contain spaces as do the

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
36,052
Location:
Prague, Czechia

Re: Additional info to try and meet posting guidelines.

So obviously it's server-side problem. In the log I can see that WinSCP successfully downloads and deletes file
/network-xfers/prod/my-download/MY ORGANISATION/my folder 1/my-xml-file-21-14 Sep 2021_1337.xml
And right after that it tries to delete folder
/network-xfers/prod/my-download/MY ORGANISATION/my folder 1
And that fails.

I see that it's S3 SFTP server. The problem might be that on S3, the folders are not required to physically exist. You can create a file that seems to exist in a folder, even if that folder actually do not exist. What can explain the problem.

And yes, as a workaround, you can download and delete files, but not folders.
Just not with simple WinSCP scripting.
See https://winscp.net/eng/docs/library_example_moves_files_keeping_directory_structure

Reply with quote

mlysons
Donor

Thank you very much, that is very interesting about the S3 servers. I will speak to the people responsible for that side of things to see if it can be addressed.

In the meantime, is there a way for me to ignore the error that WinSCP is throwing. Not ideal, I know!

Reply with quote

Advertisement

mlysons
Donor

Re: Additional info to try and meet posting guidelines.

Bingo! I've had confirmation from the supplier that deleting the folders won't work. I will be speaking to them directly now to see what we can do about this.

Thanks for your assistance :-)

Reply with quote

Advertisement

You can post new topics in this forum