I'm not familiar to command lines, still I knew the shutdown commands, but I don't know how to execute them while the file transfer in progress.
example:
this command line transfers the file, but if I subsequently give "sudo shutdown -h now" in the same terminal window then doesn't ask for password (sudo used in shutdown). It asks password after the completion of file transfer.
I don't understand what you're expecting it to do.
If the file transfer is in progress, then a shutdown will abort that transfer without completing it. That makes no sense. I would think you want the transfer to complete.
If the shutdown command is executed after the file transfer, then of course it's going to ask for the 'sudo' password then.
Instead, using osascript does the job, but sometime it is problematic that it won't force the shutdown (asking for save document, etc).
Again, I don't know what you're expecting it to do.
If you have an application open with unsaved data, then of course you should expect a shutdown to ask you to save the data. If you don't want that to happen, then save the data before starting the transfer and shutdown.
Perhaps you should think about building yourself a Workflow in Automator that performs the file transfer in Terminal, waits for it to complete, then quits Terminal. Only then do the script that tells System Events to shut down.
If the file transfer is a single shell command, then you can script that as a single action in Automator, too. That might make more sense than telling Terminal to do it. Hard to say, since you haven't explained exactly what you're trying to accomplish.
I suggest using Automator because Automator workflows are more clearly a sequence of action steps, which you don't seem to realize is also how command-lines work.