question

NaveenMareddy-6437 avatar image
0 Votes"
NaveenMareddy-6437 asked AndreaZoffoli-1155 answered

batch script in task scheduler failing to copy file to ftp server

I have task scheduler to take dbback and copy it to ftp server. But task scheduler failing with error system error code:2. However, i am able to run script manually and it successfully copied backup file to ftp server. Please help me

windows-serverwindows-server-2016
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,
Have you checked if above answers help?
If they are helpful, please do not forget to accept the answers.
Thanks

0 Votes 0 ·

Hi,
We have not heard from you for several days, any update?

0 Votes 0 ·
MotoX80 avatar image
0 Votes"
MotoX80 answered MotoX80 commented

You need to troubleshoot the commands that the .bat file is executing. In the task definition set the "Program/script" to execute cmd,exe. In the "Add arguments (optional)" field set it to "/c C:\YourFolder\YourBatFile.bat 1>C:\YourLogFolder\YourBatFile.log 2>&1".

That will capture both stdout and stderr into a log file that you can review. Use your folder and file names.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Program script >> D:\batch_files\DB_Base_backup.bat

Add arguments (optional) empty

Start In(optional)empty

Log file


2021-03-03 02:09:47.785 The system cannot find the file specified
2021-03-03 02:09:47.785 (EScpSkipFile) File or folder 'D:\test\PITR\DATABASE\BASE_BACKUP\Test_BASEBACKUP_20210303_013000.zip' does not exist.
2021-03-03 02:09:47.785 System Error. Code: 2.
* 2021-03-03 02:09:47.785 The system cannot find the file specified
. 2021-03-03 02:09:47.785 Script: Failed
. 2021-03-03 02:09:47.785 Script: Exit code: 1

0 Votes 0 ·
MotoX80 avatar image MotoX80 NaveenMareddy-6437 ·

Pretty straightforward error, it can't find the file. Not exactly something that forum users can help you with.

Does the file exist? Is the D: drive a local or a mapped drive? Add a couple of DIR commands to the bat file to verify that the file exists.

  dir D:\test\PITR\DATABASE\BASE_BACKUP\*


1 Vote 1 ·

D drive local drive not mapped drive.

First, backup will be taken and file kept in D drive later it will upload to ftp server.

When i ran manually it is working fine but it is failed on task scheduler event.

0 Votes 0 ·
Show more comments
KarlieWeng-MSFT avatar image
0 Votes"
KarlieWeng-MSFT answered

Hello @NaveenMareddy-6437

Did you enter the full path of the program in “Start In (Optional)” field?

Though the option says “optional”, the script or the executable you want to run cannot depend on the current directory being set to what you might expect. Another thing about the “Start In (Optional)” field, don’t add quotes in this field.

Even if the name of the folder or the directory contains spaces, quotes are not required nor allowed. You can do a little experiment to see if quotes can be used or not in this field. If not then just remove it.

74138-image.png

Or you could Deleted & re-created the scheduled task and Run with the highest privileges

Best Regards
Karlie


If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.






image.png (18.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreaZoffoli-1155 avatar image
0 Votes"
AndreaZoffoli-1155 answered

I also had the same problem, I solved it like this:

in the batch file you must first insert this line:

PUSHD: C \ folder containing batch file


this worked for me

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.