sftp copy file then move file moved but not copied

Advertisement

bmsitservices@outlook.com
Donor
Joined:
Posts:
1
Location:
Sydney

sftp copy file then move file moved but not copied

Hi,

Below is the script we use to copy files it then moves the files to another directory for a clients ERP software to upload
@echo off
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\temp\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://SFTP SERVER DETAILS ARE HERE"
    "get -filemask=|processed/; /production/fermexdistributors/fresho_orders/*.* c:\Capital\Capshell\CAPITAL\FRESHO_IN\Orders\*.*" ^
    "mv /production/fermexdistributors/fresho_orders/*.xml /production/fermexdistributors/fresho_orders/processed/*.xml" ^
    "exit"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
exit /b %WINSCP_RESULT%
the script works with the only issue being, Files are copied, then I think a new file is added just before the move command takes place. This file is then included in the move process. Example in the attached WinSCP log extract is file 0008599523_new_order_fermex_distributors_2023-11-23--10-56-25.xml.

It is not listed as being copied but listed as being moved, so the client does not receive the order.
Description: I am no expert in this area, I am using WinSCP at several sites and newer have an issue, any help would be much appreciated..

Reply with quote E-mail

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

Re: sftp copy file then move file moved but not copied

Making this transactionally safe cannot be easily achieved with simple WinSCP scripting.

You better use a more powerful script language. We have an example for upload in PowerShell:
Moving local files to different location after successful upload

For download, check this question on Stack Overflow (and my answer there):
Moving (not copying) remote files after download with WinSCP .NET assembly

Reply with quote

Advertisement

You can post new topics in this forum