0

I try to SFTP file to remote server using winSCP .bat script but the script keep prompt "The system cannot find the path specified." And winscp will open new session tab to other location.

File location : \pbilsr01\ACCESS BILLING\%year%\BMD Bill QA\Jun\Test

File destination : /cygdrive/d/VB_SHARE/astroQA/AFP/in

@echo off

echo %date%

set month=%date:~0,2%
echo month=%date:~0,2%

set day=%date:~3,2%
echo day=%date:~3,2%

set year=%date:~6,4%
echo year=%date:~6,4%


set LookForFile="\\pbilsr01\ACCESS BILLING\%year%\BMD Bill QA\Jun\Test\*.*"

:CheckForFile
IF EXIST %LookForFile% GOTO Eftipi
echo %time% : The file is not ready yet. Wait 5seconds


TIMEOUT /T 5 >nul
GOTO CheckForFile


:Eftipi
echo.
echo start SFTP
echo Transfering QA file from 'Pbil' folder to QA serve location:(cygdrive/d/VB_SHARE/astroQA/AFP/in)
echo Start time : %date% %time%
"C:\Program Files (x86)\WinSCP\WinSCP.exe" sftp://mebills:pass****@astrobill.com.my/ -hostkey="ecdsa-sha2********"
copy "\\pbilsr01\ACCESS BILLING\%year%\BMD Bill QA\Jun\Test" "/cygdrive/d/VB_SHARE/astroQA/AFP/in"
echo End time : %date% %time%
pause
7
  • 2
    WinSCP offers scripting interface, see Automate file transfers (or synchronization) to FTP server or SFTP server. Commented Jul 5, 2019 at 9:55
  • Your question code is not a minimal reproducible example because you have not included the code which determines one of the branches of the path, i.e. %year%. additionally, we have no idea if, at the time of running, the network location is available to the end user, perhaps using PushD "\\pbilsr01\ACCESS BILLING\%year%\BMD Bill QA\Jun\Test" would be a more sensible option. Additionally, you state file location, but your copy command will be copying all files in the top level of a directory named Test; can you please clarify the task.. Commented Jul 5, 2019 at 10:05
  • Hi @Compo, i just update my full script. What im trying to do is, to Copy all file from Test to remote server which is mebills in this location /cygdrive/d/VB_SHARE/astroQA/AFP/in Commented Jul 5, 2019 at 10:20
  • Did any files get copied? does the end user have full permissions on every file within the Test directory? Did you try using PushD, as advised? Is the code being run on exactly the same PC with the same user settings? Commented Jul 5, 2019 at 10:39
  • No file copy even if i try using PushD. It seem like the script unable to locate the destination /cygdrive/d/VB_SHARE/astroQA/AFP/in. end user have permissions to both pbil and mebills. and using the same settings. Commented Jul 5, 2019 at 11:13

1 Answer 1

1

Replace :Eftipi content to

:Eftipi
@echo off
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /command ^
    "open sftp://mebills:[email protected]/ -hostkey=""ecdsa-sha2-*****=""" ^
    "put ""\\pbilsr01\ACCESS BILLING\%year%\BMD Bill QA\Jun\Test"" "/cygdrive/d/VB_SHARE/astroQA/AFP/in" " ^
    "exit"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.