This authenticated user has write permissions on the remote server.
I can connet using sftp from the command line and write without problems.
If I put the file to the same directory where the script is, then this script works well.
I gave full permissions for this user to other directories, but it doesn't help.
This is really strange.