Close file if necessary after network error

If a network error occurs when sending a file, we now close that file,
otherwise we would use up open file entries. Also added number of
available open file entries to M111 S2 command.