1

I am transferring files through PSFTP to 3rd party server using Batch files. While transferring files, due to buffering issues, files are being broken/not transferred fully.

As a remedy, 3rd party requested us to name each file with '.new' before starting file transfer and remove '.new' once file is transferred fully/successfully.

Please let me know Batch script commands to implement above. Please let me know if you need additional info.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
saikiran
  • 71
  • 2
  • 8
  • `psftp` has a `ren` command to rename a file on a remote computer. At the `psftp` prompt type `help` and press `Enter`. The `ren` would be placed into the ftp script used to transfer the file. – lit May 30 '17 at 17:16

1 Answers1

0

To rename a file, use mv command (or it's ren alias):

put c:\local\path\file /remote/path/file.new
mv /remote/path/file.new /remote/path/file

Though if you are transferring multiple files using a wildcard, this won't help you.

A relatively simple solution for multiple files is using a temporary upload folder. After the upload finishes, you can move all files at once to the target folder:

mput c:\local\path\* /temp/path
mv /temp/path/* /remote/path

For a similar discussion, see also SFTP file lock mechanism.


If you need to use the solution with extensions, you can use WinSCP, as it allows you to automatically use a temporary file name for upload. Though it uses .filepart, not .new extension.

put -resumesupport=on c:\local\path\* /remote/path/

See WinSCP article on Uploading to temporary file name for more details.

The article also shows (a way more complicated) solution using WinSCP .NET assembly that allows you to use even the .new extension.

If you choose to switch to WinSCP, there's a guide for converting psftp script to WinSCP.

(I'm the author of WinSCP)

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992