'Returncode of sftp command is 255

I have 2 session which are almost similar, doing an SFTP in post session success command(just file name is different).

Command :

$PMRootDir/Scripts/SFTP.sh qwe.rty.com $$User /uiop $PMRootDir/SrcFiles/qwerty_$$Date.csv

Both are using the same command to send the file

SFTP.sh:

if [ -z "$EncrptedPassword" ] 
then 
    echo "Connecting to Remote Server $ServerName with user $User with Public Key Authentication"  >> ${LOG_FILE}
    echo "cd $FilePath "   >> ${LOG_FILE}
    echo "get $SourcePath/$FileName   ">> ${LOG_FILE}

    ##SFTP Connection
    sftp $UserName@$ServerName << EOF
lcd $FilePath
cd $SourcePath
get $FileName
bye
EOF

Now, both the sessions one after the other(even if the 1st session fails or succeeds, the 2nd session will start), one at 12:00:10 AM and the other session at 12:00:20 AM One session is executing fine and sending the file and the other session is failing with error code 255

when I retrigger the failed session , it runs fine again and sending the file

Any idea, what's happening ????



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source