"get" fails - no file: Can't get attributes of file / No such file or directory. / Error code: 2

Advertisement

fxdwg99
Joined:
Posts:
3

"get" fails - no file: Can't get attributes of file / No such file or directory. / Error code: 2

WinSCP get fails when there is no file and doesn’t continue to the exit command. I’m using command lines. (code listed below the examples). If I use a mget with an * in the file name it does end cleanly.

WinSCP: 5.17.10 (build 11087)
Windows Server 2019
SFTP
Scripting/automation

Logs with get:
F:\ecs>"C:\Program Files (x86)\WinSCP\WinSCP.com" /ini=nul /script="F:\ecs\z-GXS_test.txt"
echo            on
open sftp:// ******:***@FTP.xxx.com/ -hostkey="ssh-rsa 1024 4Q18VXXv3xw0xCrhpJVtIhqANlUrOf924HYGORyq0LI=" -timeout=300 -rawsettings CacheDirectories=0 CacheDirectoryChanges=0 EOLType=1
Searching for host...
Connecting to host...
Authenticating...
Using username "******".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] ******@FTP.xxx.com
cd from_cass
/from_cass
get MDBDATAAA.TXT f:\edi\ediprd\xlate\mbx\ck02521\recv\don_cassmthly.txt
Can't get attributes of file 'MDBDATAAA.TXT'.
No such file or directory.
Error code: 2
Error message from server (en): No such file.

F:\ecs>
Logs with mget:

I tried using an mget and is doesn’t fail when there is no file. It executes the exit at the end.
F:\ecs>"C:\Program Files (x86)\WinSCP\WinSCP.com" /ini=nul /script="F:\ecs\z-GXS_test.txt"
echo            on
open sftp://******:***@FTP.cassinfo.com/ -hostkey="ssh-rsa 1024 4Q18VXXv3xw0xCrhpJVtIhqANlUrOf924HYGORyq0LI=" -timeout=300 -rawsettings CacheDirectories=0 CacheDirectoryChanges=0 EOLType=1
Searching for host...
Connecting to host...
Authenticating...
Using username "******".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] ******@FTP.xxx.com
cd from_cass
/from_cass
mget MDBDATAAA.TXT* f:\edi\ediprd\xlate\mbx\ck02521\recv\don_cassmthly.txt
No file matching 'MDBDATAAA.TXT*' found.
exit

F:\ecs>
I’m on a Windows platform. We execute a bat file that calls the command lines:
z-GXS_sFTP_test.bat:
echo on
"C:\Program Files (x86)\WinSCP\WinSCP.com" /ini=nul /script="F:\ecs\z-GXS_test.txt"
Command lines with are in z-GXS_test.txt:
This version is using get:
option echo on
open sftp://cs011900:xxxxxx@FTP.xxxxxx.com/ -hostkey="ssh-rsa 1024 4Q18VXXv3xw0xCrhpJVtIhqANlUrOf924HYGORyq0LI=" -timeout=300 -rawsettings CacheDirectories=0 CacheDirectoryChanges=0 EOLType=1
cd from_cass
get MDBDATAAA.TXT f:\edi\ediprd\xlate\mbx\ck02521\recv\don_cassmthly.txt
exit
This version is using mget:
option echo on
open sftp://cs011900:xxxxxx@FTP.xxxxxx.com/ -hostkey="ssh-rsa 1024 4Q18VXXv3xw0xCrhpJVtIhqANlUrOf924HYGORyq0LI=" -timeout=300 -rawsettings CacheDirectories=0 CacheDirectoryChanges=0 EOLType=1
cd from_cass
mget MDBDATAAA.TXT* f:\edi\ediprd\xlate\mbx\ck02521\recv\don_cassmthly.txt
exit

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,390
Location:
Prague, Czechia

Re: "get" fails - no file: Can't get attributes of file / No such file or directory. / Error code: 2

That's the expected behavior.
What do you want to achieve?

Btw, note that there's no real mget in WinSCP. It's just an alias for get. They behave the same.

Reply with quote

fxdwg99
Joined:
Posts:
3

Re: "get" fails - no file: Can't get attributes of file / No such file or directory. / Error code: 2

I guess my main concern is the session closing cleanly? I don’t want to leave sessions hanging open. It never executes the exit at the end.

Yes I tested and see get and mget both can use wildcards.

This is where the other part of the question comes in. We converted our native Windows FTP to WinSCP SFTP.

In native FTP we could have more than one get in a single session. But with WinSCP failing and stopping on the first file it can’t find the other get do not execute. I had to break our one native FTP session of three get into three separate WinSCP sessions.

It looks like if we do a get with a specific file name and the file is not there WinSCP throws an error and just quits. If there other command for the session they are not executed. And the exit command at the end is not executed.

If we do a get with a wildcard and there is no file it continues on to the next command including the exit at the end.

To your other question … what would I like to achieve? It would be great if when a get on a specific file name is not found don’t end the session, go to the next command … like a get with a wildcard does.

Example of a session that does two get with a wildcards. There are no files to pull but the session goes to the second get and finally executes the exit:
cd DON_TAYLOR_TEST
/home/ftp/DON_TAYLOR_TEST
get * C:\tmp\WinSCP_test\get_data_here\
No file matching '*' found.
get * C:\tmp\WinSCP_test\get_data_here\
No file matching '*' found.
exit

C:\tmp\
Example of a session that does two get for a specific files name. The first get finds no files. The session ends and does not execute the second get or the exit:
cd DON_TAYLOR_TEST
/home/ftp/DON_TAYLOR_TEST
get don_test-1.txt C:\tmp\WinSCP_test\get_data_here\
Can't get attributes of file 'don_test-1.txt'.
No such file or directory.
Error code: 2
Error message from server: No such file

C:\tmp\

Reply with quote

rtanenbaum
Joined:
Posts:
2
Location:
USA

Continue to process next file even if the first file fails

Yes. I agree with @fxdwg99. I would like a value on the batch option that would allow the multiple gets to be processed even if the file name is fully specified (no wildcards). The option batch on and option batch continue do not cause it to continue after failing to find a file. The only way I was able to allow it to continue even if the file is not found, is to put a wildcard in the file name even if it is not needed. This worked for me, but does not feel like a clean approach. Being able to have a value for the batch option or a flag on the get command to convey the meaning of "if the file is not found just proceed like there was no error" would satisfy this need.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,390
Location:
Prague, Czechia

Re: Continue to process next file even if the first file fails

@rtanenbaum: But that's what the option batch continue does:
option batch continue
get noneexisting.txt
get existing.txt
get noneexisting.txt
Can't get attributes of file 'noneexisting.txt'.
No such file or directory.
Error code: 2
Error message from server (en): The file does not exist.
get existing.txt
existing.txt              |            3 B |    0,0 KB/s | binary | 100%   
If you have a different experience, please post a session log file.

Reply with quote

rtanenbaum

Even with option batch continue still exits with error code

Thank you Martin. Indeed it does process the file afterwards, but it still exits with an error. I was hoping to have it ignore the error altogether. My post was not clear that this was my intent. The script that calls WinSCP was checking for errors in the SFTP processing and I didn't want it to abort just because the file did not exist.

Reply with quote

Advertisement

You can post new topics in this forum