Avatar of Mitch Schwartz
Mitch Schwartz
 asked on

Error when using SHELL command to run FTP Files

I am using the following files to upload a batch of PDF files to my website:

FTP_cmd.txt
user
uploads@mywebsite.com
HM7UKZV
binary
Put SampleFile.pdf
quit

FTP_run.bat
ftp -i -s:FTP_cmd.txt mywebsite.com > FTPlog.log
Pause

When I run the FTP_run.bat file directly (through Windows Explorer), it uploads the files w/o error.

However, when I try to run the FTP_run.bat file with SHELL ("c:\uploads\FTP_run.bat"), it produces the following message in the cmd window: "Error opening script file FTP_cmd.txt. Nothing is written to the log file.

When I use SHELL ("cmd"), it opens the command window.
Microsoft AccessVBA

Avatar of undefined
Last Comment
Gustav Brock

8/22/2022 - Mon
Jim Dettman (EE MVE)

You've go no pathing on the script file in the batch file.

VBA has a current drive directory and it probably doesn't match the current location of the script file.

Try giving a full path for the script file and see if that resolves it.

Jim.
Mitch Schwartz

ASKER
I should state that all files (FTP_cmd.txt, FTP_run.bat & the files to be uploaded) are in the same directory.

I changed the bat file to ftp -i -s:c:\uploads\FTP_cmd.txt mywebsite.com.

Then I ran the bat file directly from file explorer. Got  the same error: "Error opening script file c:\uploads\FTP_cmd.txt.
Gustav Brock

Try with:

    Shell("cmd /c " & Chr(34) & "c:\uploads\FTP_run.bat" & Chr(34))

/gustav
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Mitch Schwartz

ASKER
Gustav:

I tried using your code, but it did not work. Here is what happened:

1. The command I used in an MS Access subroutine is:
Shell ("cmd /c " & Chr(34) & "c:\data\dinnerdailyapp\ftp_run.bat" & Chr(34))
2. The Access file is located in the same directory as the FTP_run.bat file and the FTP_cmd.txt file
3. After I run the SHELL command, I get an error message "Error opening script file FTP_cmd.txt".
4. In the attached screenshot of the command window after running the SHELL, it shows a path different from the location of the Access & the "FTP" files.

Contents of the FTP files:
FTP_run.bat
ftp -n -s:FTP_cmd.txt thedinnerdaily.com
Pause

FTP_cmd.txt
user
user@thedaily.com
pwKZ
binary
Put Sample01.pdf
quit

I also tried (unsuccessfully) running the FTP_run.bat file with the path to the FTP_cmd.txt file included:

ftp -n -s:c:\Data\dinnerdailyapp\FTP_cmd.txt thedinnerdaily.com
Command window after running SHELL command
ASKER CERTIFIED SOLUTION
Gustav Brock

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mitch Schwartz

ASKER
Gustav:

After I added the path to all the referenced filenames, your code worked perfectly. There was one limiting factor: If there is a space in the path, the SHELL command fails.

Thank you very much!

Mitch
Gustav Brock

You are welcome!

A path with spaces must be wrapped in double-quotes.

/gustav
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.