Batch file download called in VBA (Access) downloads to different directlry

Advertisement

packpike
Guest

Batch file download called in VBA (Access) downloads to different directlry

I have a batch file (see below) that downloads files to the directory where the batch file exists. It works great, no problems.

The problem arises when I call the batch file from inside Access with the following command. It runs the batch file, but the files get downloaded to my local Downloads directory, not the current directory. Is this something that I can/should fix inside the batch file itself?
myPath = CurrentProject.Path & "\GetFiles.bat"
Call Shell(myPath, 1)
Batch file contents
@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://XXXXXX/ -hostkey=""ssh-rsa 2048 YYYYYY"" -rawsettings ProxyPort=0" ^
    "cd outgoing" ^
    "get *" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%

Reply with quote

Advertisement

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

Re: Batch file download called in VBA (Access) downloads to different directlry

You do not specify target folder anywhere in your codes. So the script downloads the files to whatever the current working directory happens to be.

If you want to download to specific local directory, use cd command (in either the batch or in WinSCP) or specify the target path in the get command.

If you want to download to the folder of the batch file, you can use
cd /D "%~dp0"
See Change current directory to the batch file directory

Reply with quote

packpike
Guest

Thank you so much. I had tried putting in a cd, but I must have done something wrong. I added your command to the batch file and it now works whether I call it directly or from inside Access. Thanks again.

Reply with quote

Advertisement

You can post new topics in this forum