FTP script fails

lloydsmodslloydsmods Member Posts: 93
I have written the following code to use an FTP batch file to transfer files, but I'm not having any luck:
CmdFile.WRITEMODE(TRUE);
CmdFile.TEXTMODE(TRUE);
CmdFile.QUERYREPLACE(TRUE);
CmdFile.CREATE(TheCmd);
CmdFile.WRITE('prompt');
CmdFile.WRITE('USER ' + gSRSetup."Registration FTP User" + ' ' + gSRSetup."Registration FTP Passwd");
CmdFile.WRITE('cd ' + fbox);
CmdFile.WRITE('mget *.TXT');
CmdFile.WRITE('mget *.txt');
CmdFile.WRITE('bye');
CmdFile.CLOSE;

BatchFile.WRITEMODE(TRUE);
BatchFile.TEXTMODE(TRUE);
BatchFile.QUERYREPLACE(TRUE);
BatchFile.CREATE(TheBat);
BatchFile.WRITE('ftp -n -s:' + tCMD + ' ' + gSRSetup."Registration FTP Path");
BatchFile.CLOSE;

This works as far as it creates the command file and the batch file in the correct folder. So far so good.
CREATE(WScript);
WScript.Exec(TheBat);
CLEAR(WScript);

WScript is the automation object 'Windows Script Host Object Model'.WshShell.

This appears to run something, but it flashes quickly. What it doesn't do is execute the FTP script. Nothing gets downloaded.

If you run the batch file manually it works perfectly, the files download. The code just doesn't seem to work. What did I miss?
If guns cause crime mine must be defective.

Comments

  • PeterVersteegePeterVersteege Member Posts: 13
    It could be that it just goes to quick when you excute the code: I think it is good to try to add an extra pause of 1 or more seconds before starting the script. It could be that the batch-file is still in use when starting the script.
    K3 Business Solutions
  • lloydsmodslloydsmods Member Posts: 93
    Thanks for the suggestion Peter. I tried that this morning, even waiting 10 second. No luck.

    Out of desperation I even replaced the WScript code with a SHELL command.
    SHELL(TheBat);
    

    That did at least connect to the FTP server, but it gave me I/O Errors and transferred nothing. Grrr.
    If guns cause crime mine must be defective.
  • lloydsmodslloydsmods Member Posts: 93
    I even tried the script from this link http://www.nextequalzero.com/2007/06/unattended-ftp-upload-from-dynamics-nav/, but the same thing happens. DOS box flashes, nothing imports.
    If guns cause crime mine must be defective.
  • KYDutchieKYDutchie Member Posts: 345
    Hi,

    I've done it before and this is how I did it:
    tsFTPScriptName := 'c:\tsFTPScript';
    tsCreateFTPScript;
    WHILE NOT EXISTS(tsFTPScriptName) DO
       SLEEP(500);
    
    tsWindowStyle := 1;
    tsWait := TRUE;
    tsAuto.Run(tscommand2,tsWindowStyle,tsWait);
    

    Where tsAuto is the automation "Windows Script host Object Model".WSHELL.

    Also my ftp script that gets created looks like:
    OPEN <ftphostname>
    <username>
    <password>
    bin
    mget *.txt
    quit


    And tscommand2 := 'ftp -s:c:\tsFTPscript'
    tsWait is a variable of type VARIANT. It did not work with the boolean.
    tsWindowStyle is also a variable of type VARIANT.

    This has been working for a couple of years now.

    Hope this helps,

    Regards,

    Willy
    Fostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.
  • lloydsmodslloydsmods Member Posts: 93
    Thanks Willy. I tried your code but I get the same result that I get when using the SHELL command: I/O errors. I'm stumped.
    If guns cause crime mine must be defective.
  • KYDutchieKYDutchie Member Posts: 345
    What are the IO errors you are getting. They might indicate us into the right direction.

    Also what is the OS where the client is running. You might be dealing with a UAC or other security problem.

    Thanks,

    Willy
    Fostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.
  • lloydsmodslloydsmods Member Posts: 93
    dos-fail.gif

    This is the result I get.
    If guns cause crime mine must be defective.
  • lloydsmodslloydsmods Member Posts: 93
    I'm testing on a Windows 7 system. Let me see if I get the same result on my client's Windows Server 2008.
    If guns cause crime mine must be defective.
  • KYDutchieKYDutchie Member Posts: 345
    This looks like ftp cannot move the temp file to the target folder.

    Do the files already exist in the target folder? If so, try to move them and then try the FTP again.

    Maybe it is something simple like this :D
    Fostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.
  • lloydsmodslloydsmods Member Posts: 93
    Nope same thing on the client's server.
    If guns cause crime mine must be defective.
  • lloydsmodslloydsmods Member Posts: 93
    The local target folder is empty.
    If guns cause crime mine must be defective.
  • KYDutchieKYDutchie Member Posts: 345
    Hi,

    your code is this:
    BatchFile.WRITEMODE(TRUE);
    BatchFile.TEXTMODE(TRUE);
    BatchFile.QUERYREPLACE(TRUE);
    BatchFile.CREATE(TheBat);
    BatchFile.WRITE('ftp -n -s:' + tCMD + ' ' + gSRSetup."Registration FTP Path");
    BatchFile.CLOSE;
    

    can you try:
    BatchFile.WRITEMODE(TRUE);
    BatchFile.TEXTMODE(TRUE);
    BatchFile.QUERYREPLACE(TRUE);
    BatchFile.CREATE(TheBat);
    Batchfile.Write('CD \temp');  //Or any other directory that can be accessed
    BatchFile.WRITE('ftp -n -s:' + tCMD + ' ' + gSRSetup."Registration FTP Path");
    BatchFile.CLOSE;
    

    I think you might be in the wrong directory to do this. You might in a directory where you don't have enough rights to save files. For testing purposes, try ftp the files to the "temp" directory. Also make sure your FTP command script is in the directory you are using.

    Regards,

    Willy
    Fostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.
  • lloydsmodslloydsmods Member Posts: 93
    That doesn't work either. My original script worked if you ran it manually, if you simply double clicked the BAT file it would connect and transfer the files. When I try to execute the batch file using NAV it doesn't work.
    If guns cause crime mine must be defective.
  • fredefrede Member Posts: 80
    Hi,

    maybe you could use the "lcd" command in your ftp script to make sure that the local directory is the correct one when downloading.

    Also I've experienced problems with up- and downloading and found that by stating "binary" to make sure datatransfer is in binary has solved the problem.

    But I have stopped download directly from NAV via NAS because I experienced that every other day the ftp command stops on the server...

    Now my ftp download is run from a seperate scheduler and it works every time...(sorry to say)

    Best regards,
    Regards,

    Henrik Frederiksen, Denmark
  • danlindstromdanlindstrom Member Posts: 130
    lloydsmods wrote:
    dos-fail.gif

    This is the result I get.

    You are probably down loading to a folder that you DONT have write permission to! Like 'c:\' or 'c:\program files'. These are by default readonly by the OS.
    Use lcd to a writeable directory.
    after or before the line
    CmdFile.WRITE('cd ' + fbox);
    
    CmdFile.WRITE('USER ' + gSRSetup."Registration FTP User" + ' ' + gSRSetup."Registration FTP Passwd");
    CmdFile.WRITE('bin');
    CmdFile.WRITE('cd ' + fbox);
    CmdFile.WRITE('lcd c:\temp');
    CmdFile.WRITE('mget *.TXT');
    


    frede wrote:
    Hi,

    maybe you could use the "lcd" command in your ftp script to make sure that the local directory is the correct one when downloading.

    Also I've experienced problems with up- and downloading and found that by stating "binary" to make sure datatransfer is in binary has solved the problem.

    But I have stopped download directly from NAV via NAS because I experienced that every other day the ftp command stops on the server...

    Now my ftp download is run from a seperate scheduler and it works every time...(sorry to say)

    Best regards,

    We had problems with hanging transmissions (and blocking NAS) at customer and solved by using a ftp-client with has support for timeouts, like NcFTP Here
    Regards
    Dan Lindström
    NCSD Navision 2.00 since 1999 (Navision Certified Solution Developer)
    MBSP Developer for Microsoft Dynamics NAV 2009
Sign In or Register to comment.