Link to home
Start Free TrialLog in
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.
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

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.
Avatar of Mitch Schwartz
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.
Try with:

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

/gustav
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
User generated image
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
You are welcome!

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

/gustav