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.
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")
When I use SHELL ("cmd"), it opens the command window.
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.
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
Shell("cmd /c " & Chr(34) & "c:\uploads\FTP_run.bat" & Chr(34))
/gustav
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\ft p_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.tx t thedinnerdaily.com
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\ft
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\
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
A path with spaces must be wrapped in double-quotes.
/gustav
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.