1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

mput doesn't work correctly when run in task scheduler

Discussion in 'Windows XP' started by supphavith09, 2012/02/08.

  1. 2012/02/08
    supphavith09

    supphavith09 Inactive Thread Starter

    Joined:
    2012/02/08
    Messages:
    1
    Likes Received:
    0
    I have a .bat file to ftp upload a document to a sharepoint ftp server. When I manually run it, it works with no problem and the files are uploaded.
    However, when I run it using the task scheduler, it runs but the files are not uploaded (when I run manually, the file names are specified after the 'mput' command in the cmd, but when i use task scheduler, the fields after 'mput' is just blanks).
    Please help :confused:!?

    The script is as follows.

    Code:
    @Echo Off
    Setlocal Enabledelayedexpansion
    
    REM -- Define File Filter, i.e. files with extension .txt
    Set FindStrArgs=/E /C: ".xlsx "
    
    REM -- Extract Ftp Script to create List of Files
    Set  "FtpCommand=ls "
    Call:extractFileSection  "[Ftp Script 1]"  "- "> "%temp%\%~n0.ftp "
    Rem Notepad  "%temp%\%~n0.ftp "
    
    REM -- Execute Ftp Script, collect File Names
    Set  "FileList= "
    For /F  "Delims=" %%A In (' "Ftp -v -i -s: "%temp%\%~n0.ftp "|Findstr %FindStrArgs% "') Do (
        Call Set  "FileList=%%FileList%%  "%%A" "
    )
    
    REM -- Extract Ftp Script to upload files that don't exist in remote folder
    Set  "FtpCommand=mput "
    For %%A In (%FileList%) Do set  "Exist[ "%%~A"]=Y "
    For /F  "Delims=" %%A In (' "dir /b  "%localdir% "|Findstr %FindStrArgs% "') Do (
        If Not defined Exist[ "%%~A"] Call Set  "FtpCommand=%%FtpCommand%%  "%%~A" "
    )
    Call:extractFileSection  "[Ftp Script 1]"  "- "> "%temp%\%~n0.ftp "
    rem  Notepad  "%temp%\%~n0.ftp "
    
    For %%A In (%FtpCommand%) Do Echo.%%A
    
    REM -- Execute Ftp Script, download files
    ftp -i -s: "%temp%\%~n0.ftp "
    Del  "%temp%\%~n0.ftp "
    GOTO:EOF
    
    
    :extractFileSection StartMark EndMark FileName -- extract a section of file that is defined by a start and end mark
    ::                  -- [IN]     StartMark - start mark, use '...:S' mark to allow variable substitution
    ::                  -- [IN,OPT] EndMark   - optional end mark, default is first empty line
    ::                  -- [IN,OPT] FileName  - optional source file, default is THIS file
    :$created 20080219 :$changed 20100205 :$categories ReadFile
    :$source [url]http://www.dostips.com[/url]
    SETLOCAL Disabledelayedexpansion
    set  "bmk=%~1 "
    set  "emk=%~2 "
    set  "src=%~3 "
    set  "bExtr= "
    set  "bSubs= "
    if  "%src% "==" " set src=%~f0&        rem if no source file then assume THIS file
    for /f  "tokens=1,* delims=]" %%A in ('find /n /v " "  "%src% "') do (
        if /i  "%%B "== "%emk%" set  "bExtr= "&set  "bSubs= "
        if defined bExtr if defined bSubs (call echo.%%B) ELSE (echo.%%B)
        if /i  "%%B "== "%bmk%"   set  "bExtr=Y "
        if /i  "%%B "== "%bmk%:S" set  "bExtr=Y "&set  "bSubs=Y "
    )
    EXIT /b
    
    
    [Ftp Script 1]:S
    !Title Connecting...
    open sharepointftp.barcapint.com 21
    mydomain\myusername
    mypassword
    
    !Title Preparing...
    cd rfertbapplicationmanagement/infrastructure/ "Estate Management "/ "Daily Infra Heatmap "/Y2012
    lcd Y:\Sgp\IT\Risk\Projects\Infra\WWH\ "Daily Heatmaps "\upload
    binary
    hash
    
    !Title Processing... %FtpCommand%
    %FtpCommand%
    
    !Title Disconnecting...
    disconnect
    bye
     
  2. 2012/02/10
    mattman

    mattman Inactive Alumni

    Joined:
    2002/06/10
    Messages:
    8,198
    Likes Received:
    63
    Where did you get the script? Best ask those that wrote it.

    We are not programmers, we try to troubleshoot end-user's problems.

    Ask yourself why the file might run differently. It obviously works.

    For a laugh :), try adding it into your Start -> Programs -> Startup folder, and see if it runs when you log in.

    Matt
     

  3. to hide this advert.

  4. 2012/02/10
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,072
    Likes Received:
    400
    When is the task scheduled to run?

    If the computer is in standby mode when the script runs, it may fail because the network adapter may be shut down during standby. If that's the case, change power management settings for the adapter.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.