Bat file doesn't work with Task Scheduler

2025-03-20T23:31:37.1333333+00:00

I have a bat file that copies 3 txt files to an ftp directory, Task Scheduler launches it daily. The Task Scheduler history says "Task Scheduler successfully finished" and I get no errors. When I look in the ftp directory my files are not there.

But, when I launch the bat file from CMD it works.

Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

9 answers

Sort by: Most helpful
  1. MotoX80 36,401 Reputation points
    2025-03-21T00:33:18.35+00:00

    You need to capture stdout and stderr to see what output the bat file produces.

    See my answer to this question as to how to configure the task actions to do that.

    https://learn.microsoft.com/en-us/answers/questions/2141466/how-to-run-a-task-with-task-scheduler

    0 comments No comments

  2. Neff, Stephen [COMRES/COLDCHAIN/BOI] 0 Reputation points
    2025-03-21T14:54:49.6266667+00:00

    I have the output of the bat file going to a log, here is the output:

    C:\Users\Stephen.Neff\ZZZ Omnify\EtQ Data>"C:\Users\Stephen.Neff\ZZZ Omnify\EtQ Data\Batch FTP File Upload.bat"1>"C:\Users\Stephen.Neff\ZZZ Omnify\EtQ Data\LogFile.txt" 2>&1

    C:\Windows\System32>set FTP_SERVER=relianceftp.copeland.com

    C:\Windows\System32>set FTP_USER=reliance

    C:\Windows\System32>set FTP_PASS=ftp4reliance

    C:\Windows\System32>set LOCAL_FILE1="C:\Users\Stephen.Neff\ZZZ Omnify\CLD_Cargo_Suppliers.txt"

    C:\Windows\System32>set LOCAL_FILE2="C:\Users\Stephen.Neff\ZZZ Omnify\CLD_Cargo_SuppliersParts.txt"

    C:\Windows\System32>set LOCAL_FILE3="C:\Users\Stephen.Neff\ZZZ Omnify\CLD_Cargo_Parts.txt"

    C:\Windows\System32>set REMOTE_DIR=CLD

    C:\Windows\System32>echo open relianceftp.copeland.com 1>ftpcmd.txt

    C:\Windows\System32>echo reliance 1>>ftpcmd.txt

    C:\Windows\System32>echo ftp4reliance 1>>ftpcmd.txt

    C:\Windows\System32>echo cd CLD 1>>ftpcmd.txt

    C:\Windows\System32>echo binary 1>>ftpcmd.txt

    C:\Windows\System32>echo put "C:\Users\Stephen.Neff\ZZZ Omnify\CLD_Cargo_Suppliers.txt" 1>>ftpcmd.txt

    C:\Windows\System32>echo put "C:\Users\Stephen.Neff\ZZZ Omnify\CLD_Cargo_SuppliersParts.txt" 1>>ftpcmd.txt

    C:\Windows\System32>echo put "C:\Users\Stephen.Neff\ZZZ Omnify\CLD_Cargo_Parts.txt" 1>>ftpcmd.txt

    C:\Windows\System32>echo bye 1>>ftpcmd.txt

    C:\Windows\System32>ftp -s:ftpcmd.txt

    C:\Windows\System32>del ftpcmd.txt

    C:\Windows\System32>echo FTP Upload Complete

    FTP Upload Complete

    Again the bat file "works" if it is not run in Task Scheduler

    0 comments No comments

  3. Michael Taylor 60,326 Reputation points
    2025-03-21T15:04:09.91+00:00

    Your script is using what I assume is your local account path. Did you configure your scheduled task to run under your local account? If not then it won't have access to the files under your Users directory.

    0 comments No comments

  4. MotoX80 36,401 Reputation points
    2025-03-21T16:00:15.8366667+00:00

    C:\Windows\System32>echo reliance 1>>ftpcmd.txt C:\Windows\System32>echo ftp4reliance 1>>ftpcmd.txt C:\Windows\System32>echo cd CLD 1>>ftpcmd.txt C:\Windows\System32>echo binary 1>>ftpcmd.txt

    If your current working directory is C:\Windows\System32 then an access denied error somewhere in your log would not be unexpected.

    Add a "cd C:\Users\Stephen.Neff\ZZZ Omnify" to the script, or fully qualify all references to ftpcmd.txt.

    echo reliance 1>> "C:\Users\Stephen.Neff\ZZZ Omnify\ftpcmd.txt"
    
    
    

    Add a type command into the script and verify that the contents of the ftpcmd.txt file is getting set correctly.

    type "C:\Users\Stephen.Neff\ZZZ Omnify\ftpcmd.txt"
    type ftpcmd.txt
    

    I would also expect to see the output from ftp.exe in your log. Something isn't right there.

    0 comments No comments

  5. Neff, Stephen [COMRES/COLDCHAIN/BOI] 0 Reputation points
    2025-03-21T16:15:47.24+00:00

    here is what the log file looks like when it works:

    C:\Users\Stephen.Neff\ZZZ Omnify\EtQ Data>"C:\Users\Stephen.Neff\ZZZ Omnify\EtQ Data\Batch FTP File Upload.bat"1>"C:\Users\Stephen.Neff\ZZZ Omnify\EtQ Data\LogFile.txt" 2>&1

    ftp> open relianceftp.copeland.com

    Connected to P01GDCFTP.copeland.org.

    220 usstlcspzzzap86.emrsn.org X2 WS_FTP Server 9.0.1(35593723)

    200 Command OPTS succeed

    User (P01GDCFTP.copeland.org:(none)):

    331 Enter password

    230 User logged in

    ftp> cd CLD

    250 Command CWD succeed

    ftp> binary

    200 Transfer mode set to BINARY

    ftp> put "C:\Users\Stephen.Neff\ZZZ Omnify\CLD_Cargo_Suppliers.txt"

    200 Command PORT succeed

    150 Uploading in BINARY file CLD_Cargo_Suppliers.txt

    226 Transfer completed

    ftp: 3625 bytes sent in 0.06Seconds 62.50Kbytes/sec.

    ftp> put "C:\Users\Stephen.Neff\ZZZ Omnify\CLD_Cargo_SuppliersParts.txt"

    200 Command PORT succeed

    150 Uploading in BINARY file CLD_Cargo_SuppliersParts.txt

    226 Transfer completed

    ftp: 7632 bytes sent in 0.06Seconds 131.59Kbytes/sec.

    ftp> put "C:\Users\Stephen.Neff\ZZZ Omnify\CLD_Cargo_Parts.txt"

    200 Command PORT succeed

    150 Uploading in BINARY file CLD_Cargo_Parts.txt

    226 Transfer completed

    ftp: 18049 bytes sent in 0.13Seconds 134.69Kbytes/sec.

    ftp> bye

    221 bye

    And I added the 2 lines with TYPE in them and nothing


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.