Help with moving files on remote server using sftp

I need to sftp a file ABC_sysdate.csv (File name with system date and timestamp) to a temporary directory on the remote server and once the file is copied I've to move the file from temporary directory to the main directory with the same name.
I have to generate a new file every hour and repeat the sftp process.How can I do that using a unix script?

scp is an ssh client that does file copies and file moves on remote systems. Generally if you have sftp access, and are not in a chroot jail on the remote, you can do this also assuming ssh keys and permissions are correctly set on remotebox:

scp remotebox:/path/to/file/filename remotebox:/tmp/path/filename
sftp remotebox <<! EOF
   mkdir /path/to/new/file/
   exit
EOF
scp remotebox:/tmp/path/filename  remotebox:/path/to/new/file/filename

Thanks for the response Jim.

I don't have permissions to create directory on the remote server. I need to place a file from unix server using sftp to temporary directory and move all the files to another directory.

Is there any alternate option?

Well if your destination directory already exists then simply scp the file and then use ssh to move it:

scp -p ABC_sysdate.csv remotebox:/tmp/
ssh remotebox "mv /tmp/ABC_sysdate.csv /path/to/new/file/"

Hi Chubler,

Thanks for your response but I don't have ssh access, all I have is sftp access.

First I need to sftp the file from my linux box to temporary directory on the remote server and then move the file to main directory on the remote server.

Also, can we use *.csv while moving the file because the timestamp on the file name keeps on changing?

Unfortunately, I am unaware of any mechanism of moving remote files using sftp. Perhaps you could transfer them to a "intransit" name in the destination directory and then rename, this is what rsync does.

scp -p ABC_sysdate.csv remotebox:/upload/path/.intransit.ABC_sysdate.csv
sftp remotebox <<EOF
   rename /upload/path/.intransit.ABC_sysdate.csv /upload/path/ABC_sysdate.csv 
   exit
EOF

The -p option of scp should preserve permissions and file times

Yes you can use *.csv.
Can you have someone who has access to the remote server, create a cron job that moves any files in your inbound directory to the place where they need to be. Alternatively, can the inbound directory that you have access to be soft linked to the final destination directory.