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.
LVL 1
ms3930Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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.
ms3930Author Commented:
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 BrockCIOCommented:
Try with:

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

/gustav
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

ms3930Author Commented:
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
Gustav BrockCIOCommented:
You also need the full path to the document. Then it will run:
r:\cd_test12>ftp -n -s:c:\test\FTP_cmd.txt cactus.dk
Connected to cactus.dk.
220 Microsoft FTP Service
200 OPTS UTF8 command successful - UTF8 encoding now ON.
ftp> user
Username xyz
331 Password required

230 User logged in.
ftp> binary
200 Type set to I.
ftp> cd lib
250 CWD command successful.
ftp> put c:\test\test.pdf
200 PORT command successful.
125 Data connection already open; Transfer starting.
226 Transfer complete.
ftp: 241794 bytes sent in 1.66Seconds 145.75Kbytes/sec.
ftp> quit
221 Goodbye.

r:\cd_test12>pause
Press any key to continue . . .

Open in new window

/gustav

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ms3930Author Commented:
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 BrockCIOCommented:
You are welcome!

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

/gustav
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.