WatchDirectory home page
WatchDirectory Startseite (Deutsche Version)
Site WatchDirectory (Français)
  Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
   
  HomeHelpSearchLoginRegister  
 
Page Index Toggle Pages: 1
Batch File that does FTP (Read 6554 times)
Verne
Junior Member
**
Offline



Posts: 50
Batch File that does FTP
Apr 29th, 2014 at 8:47pm
 
I have dozens of Watch Directory tasks that execute Batch files that do nothing more than a predefined ftp with a ftp script.  They all work flawlessly.

Today I wrote a pretty lengthy batch file and the very last step is an ftp step.  Basically the Batch file is converting a file to a different format. Zipping up some other files.  The last step is to ftp those files.  I just use a couple of echo commands to create an ftp script.  I then execute the ftp script and redirect the output to a log file.  We redirect the output to a log file for all of our FTP batch files but on this particular batch file the LOG output is not correct.

What is really bizarre is if I manually execute the batch file the verbose output from the ftp command writes out to the log file.  If WatchDirectory executes the batch file, somehow the ftp script gets written to the ftp log.

It is pretty basic code. We use this same code in all of our batch files
Code:
echo Running FTP.
C:\WINDOWS\system32\ftp.exe -n -i -s:"FTPScript.txt">FTP_Transfer.log 



When I run the batch file manually I get my desired output in the log file.
My script file when I run it manually.
Code:
open ftp.mydomain.com
user username
password
cd "From De Pere/Client/88888"
put "C:\DBF_Convert\Output\88888_4444_PREFERRED.dbf"
put "C:\DBF_Convert\Output\88888_4444_PREFERRED_maildats.zip"
quit 


The Log file when I run it manually.
Code:
ftp> Connected to ftp.mydomain.com.
open ftp.mydomain.com
220-FTP
   WARNING!  By accessing and using this system you are consenting to system monitoring for enforcement of company policy and other purposes.  Unauthorized use of this computer system may subject you to criminal prosecution and penalties.
220 FTP
ftp> user username
331 Enter password

230 User logged in
ftp> cd "From De Pere/Client/88888"
250 Command CWD succeed
ftp> put "C:\DBF_Convert\Output\88888_4444_PREFERRED.dbf"
200 Command PORT succeed
150 Uploading in BINARY file 88888_4444_PREFERRED.dbf
226 Transfer completed
ftp: 23705522 bytes sent in Seconds Kbytes/sec.
ftp> 19.211234.28put "C:\DBF_Convert\Output\88888_4444_PREFERRED_maildats.zip"
200 Command PORT succeed
150 Uploading in BINARY file 88888_4444_PREFERRED_maildats.zip
226 Transfer completed
ftp: 367611 bytes sent in Seconds Kbytes/sec.
ftp> 0.241506.60quit
221 bye 



Everything looks good so far.
Now look at the ftp log file when Watch Directory runs the batch file.
Code:
open ftp.mydomain.com
user username

cd "From De Pere/Client/88888"
put "C:\DBF_Convert\Output\88888_4444_PREFERRED.dbf"
put "C:\DBF_Convert\Output\88888_4444_PREFERRED_maildats.zip"
quit 


I have no idea how the ftp script is getting put into the log file.  Redirecting the verbose output from the ftp command works on every batch file I have written except for this one.

I do have Capture output from .bat files checked.  Is this what is causing the issue?
Back to top
 
 
IP Logged
 
Verne
Junior Member
**
Offline



Posts: 50
Re: Batch File that does FTP
Reply #1 - Apr 29th, 2014 at 9:02pm
 
I unchecked the Capture Output and I still get the ftp script being written to the ftp log instead of the verbose output from the ftp command written to the log.
Back to top
 
 
IP Logged
 
Verne
Junior Member
**
Offline



Posts: 50
Re: Batch File that does FTP
Reply #2 - Apr 29th, 2014 at 9:57pm
 
Well I guess I found a short term work around but that doesn't explain what is going on with the log file not getting the verbose output from the ftp command.

I created a task to Start Any Program.
I selected cmd.exe at the executable to run.
For the startup directory I chose the location of the batch file.
I then passed these parameters /C DB_Auto.bat

Now I get the verbose output from the FTP command into the log file.

Run Any Bat file plugin doesn't seem to like my batch file.  I will email it to Gert to see if he sees anything funny in it.
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2232
The Netherlands
Re: Batch File that does FTP
Reply #3 - Apr 30th, 2014 at 8:04am
 
I have looked at your script and see no reason for this issue. Strange.

I see you are only redirecting stdout to the log, perhaps you should also redirect stderr to catch the error messages.

so change
Code:
ftp.exe -n -s:"FTPScript.txt" > "C:\BatchLogFiles\FTP_Transfer.log" 


to
Code:
ftp.exe -n -s:"FTPScript.txt" > "C:\BatchLogFiles\FTP_Transfer.log" 2>&1 



or remove all redirection, make sure "ECHO ON" and use the technique "debugging your .bat file" described here: http://www.watchftp.com/wfhelp/troubleshooting_en.html


Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Verne
Junior Member
**
Offline



Posts: 50
Re: Batch File that does FTP
Reply #4 - Apr 30th, 2014 at 2:58pm
 
Pretty sure you don't need to redirect standard error to the log file.  I never use standard error and error messages from the ftp command still get redirected into the log file.

I will see if I can debug it some more.  Spent most of the day trying to do that but couldn't figure it out.
Back to top
 
 
IP Logged
 
Verne
Junior Member
**
Offline



Posts: 50
Re: Batch File that does FTP
Reply #5 - Apr 30th, 2014 at 5:21pm
 
Redirecting Standard Error did not make a difference.  Basically whatever is in the ftp script gets put into the ftp log file.

This is very strange because Verbose output is on by default when you execute ftp.  I would physically have to turn it off in the script file to not get any verbose output.
Back to top
 
 
IP Logged
 
Page Index Toggle Pages: 1