Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

packpike

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.
martin

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
packpike

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%