How to overwrite a file by transferring the file using sftp?

hi,

i am using sftp to transfer files between two servers,

if i connect to a remote server using sftp n moves a file say "S123.txt" to the remote server, it moves successfully, but when i try to execute the same sftp script to move the same files to the same remote server, the old file is not replaced with the new one. i want the new file to overwrite the old file. how can i do this.. is there a command in sftp which forcely overwrites the old file.

If the filename is the same, it is usually overwritten with the new file, just as you tried it on the command line.
Do you get a message when it can't be overwritten? Do you write any log output from your script?

no i dint get any such message in the log file. but the arrival time of the file was not changed so i thought its the old file.

  1. confirm that the time stamp of the new file on the local server is different from the time stamp of the file at the remote server ... ls -l $local_file and ls -l $remote_file

  2. if time stamps are the same, touch $local_file and confirm $local_file time stamp changed with ls -l $local_file ...

  3. run sftp job to transfer $local_file to remote server ...

  4. confirm time stamps again ...

if time stamps are now the same, sftp transfer overwrite is successful ...

if time stamps are still different, check logs on remote server for any issues ...