Running a batch file in Task Scheduler to upload a zipped file to an FTP site

I have this batch file running on a Win2008 Server below and I am trying to upload a fairly large file nightly 50 mb and growing.

@echo off
(echo open 111.111.111.111
echo user username passwordhere
echo cd /BackupSunRiver
echo binary
echo put "C:\Users\Public\Pictures\pb210027.jpg"
echo quit
) | ftp -n -i

If I run this batch file from Task Scheduler it stays stuck in the "Running position" and never finishes.
If I right click on the batch file and say run as administrator the batch runs and the file is uploaded.
What am I doing wrong? Oh I used a smaller file for testing above. Not the 50mb one.
Fletcher BurdineTableau Trainer & Consultant Sales Exec.Asked:
Who is Participating?
 
dexITConnect With a Mentor Commented:
Yes. Once you've filled in the credentials, go into task scheduler, right click go to properties, go to the security tab and make sure the credentials being used are listed with rights.
0
 
richardcardinConnect With a Mentor Commented:
Are you using the same account to run the test in scheduler? If not, use the same account in the credentials for the task to run. Thanks
0
 
dexITCommented:
You'll need to assign administrator rights to the account that will be performing this upload. domain\user
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
dexITCommented:
Make sure the account being used also has the appropriate rights to the scheduled task itself.
0
 
Fletcher BurdineTableau Trainer & Consultant Sales Exec.Author Commented:
Sorry gentlemen I do not know how to code that can you elaborate and give me the steps. I struggled to get what you see above also with help from EE gurus. Thank you
0
 
Fletcher BurdineTableau Trainer & Consultant Sales Exec.Author Commented:
When I log in I am an Administrator user. Part of that group and should have full rights. When I adjust or EDIT a segment of the task scheduler I am forced to put in a user name and password. I use my own. It passes the login and seems to hold those credentials for when it runs. However it will stay stuck in running mode for hours if I do not end it. Nothing happens until I end the task.

However if I take the files and double click the batch file it runs and uploads the file perfectly or I can  right click and choose run as administrator and that too also works. Scheduling it run by going into Task Scheduler itself and right clicking and choosing RUN does not work it hangs with no result.

Any thoughts on what could be causing this..... please advise. And thank you for just being here.
0
 
Fletcher BurdineTableau Trainer & Consultant Sales Exec.Author Commented:
Ah that will turn your face red. I was thinking there was code in that. You just stated login as the actual Administrator with his password rather than my own witch may be an Administrator it is not authorized to use the FTP. Apparently the Administrator is. You said Domain\Administrator  and the password. Correct?
0
 
Fletcher BurdineTableau Trainer & Consultant Sales Exec.Author Commented:
Okay so that you know we tried that on the Win 2008 Server machine. We selected task and the properties and reset the user and password to the \SERVERNAME\Administrator and his password.
We were wondering if it was the Check Run with Highest Privedges
or Something in the Microsoft Firewall. We have no Antivirus at all on this machine so it is not that. When we went into the Firewall and looked the FTP box was checked so we are baffled.
If you have any ideas please feel free. We have struggled with this for months. Thank you.

0
 
Tomas Helgi JohannssonCommented:
      Hi!

When you created the Task in Win2008.
Did you check the "Run whether user is logged on or not" or "Run only when user is logged on" ?

You should check the first one ;)

Regards,
    Tomas Helgi
0
 
Tomas Helgi JohannssonConnect With a Mentor Commented:
Also make sure that the user running the Task
has access to the FTP server.
If not you have to grant that access to the user in the FTP server itself.

Regards,
    Tomas Helgi
0
 
yogi4lifeConnect With a Mentor Commented:
Your should split line 3 into two lines:

from:
echo user username passwordhere

to:

echo user username
echo passwordpasswordhere

As FTP will regard your username as "username passwordhere" ... which is probably not what you want?

@echo off
(echo open 111.111.111.111
echo user username 
echo passwordhere
echo cd /BackupSunRiver
echo binary
echo put "C:\Users\Public\Pictures\pb210027.jpg"
echo quit
) | ftp -n -i

Open in new window

0
 
Justin_W_ChandlerConnect With a Mentor Commented:
I'm sorry to say that you will have to give up on this solution. It has been shown MANY times that the Windows task scheduler does not properly execute batch files of any type. Sadly, Microsoft has not corrected this 10 year old problem yet.
0
 
yogi4lifeCommented:
Justin, I think you should not make such a claim without any reference to support it. It might be some problems to get batch files to run if you don't run the background jobs/tasks with the right privileges and possibly you would have to invoke either command.com or cmd.exe where actually the batch-commands "live" ... but that is something entirely different than claiming that "batch files of any type" won't execute properly...

Your comment is not helpful - and it is off-topic...
0
 
Justin_W_ChandlerCommented:
There are numerous references to this same issue all over the web. I sincerely hope you can find a solution to the issue, you will be a hero to the community. Good luck :)
0
 
BillDLConnect With a Mentor Commented:
You say that if the given batch file is called by Task Scheduler "it stays stuck in the 'Running position' and never finishes".

What exactly is you command in Task Scheduler?

When you chose your "Program To Run", did you just browse to the Batch file, OR did you browse to CMD.EXE and then set the command line parameter as the Path To and Name Of the batch file to run?  ie. something like this:

%SystemRoot%\System32\CMD C:\Name_Of_Batch_File.cmd
OR
%SystemRoot%\System32\CMD /K C:\Name_Of_Batch_File.cmd

If that is the case, then try changing the /K switch to /C or just adding the /C switch if it isn't there in the command to be executed, like this:

%SystemRoot%\System32\CMD /C C:\Name_Of_Batch_File.cmd

The default of Task Scheduler for CMD.EXE seems to be the /K switch.
CMD.EXE /C Command          Executes command then terminates.
CMD.EXE /K Command          Executes the command but remains.
0
 
Fletcher BurdineTableau Trainer & Consultant Sales Exec.Author Commented:
dexIT & TomasHelgi:

I posted what I have setup below. I am part of the Administrators group. I have access to virtually everything on that machine. I have not tried every single file and folder but I am part of that group. I have tried using the Administrator's login as well not with the /c or the /k input yet.
BillDL:
 I noticed that you put the extension .cmd at the end of your line
%SystemRoot%\System32\CMD C:\Name_Of_Batch_File.cmd
Mine has the extension .bat is that where I made the mistake? I thought it had to be a  '.bat '?

yogi4life:
I noticed that your support said to add a second line which I did. You line shows this
echo user username
echo passwordhere

I put in
echo user username
echo  ' just the password '
"Was I supposed to put in the WORD "password"  in front of "THE ACTUAL PASSWORD" (with a space between)?  like : echo password THEACTUALPASSWORD

Justin_W_Chandler:
This is not the first time I have heard that comment. Either something is fishy about Microsoft task scheduler that is not common knowledge or the code is so tricky with all the variables in place that using the task scheduler is difficult to say the least. (I have worked on this for 4 months trying to get this right as a low cost solution to backups for clients) If I do not get this resolved I may go broke trying.

Again for a refresher. I can double click the Batch file and it uploads immediately. I can also right click on the file and choose run as Administrator and it uploads as well. It only refuses to work in the Task Scheduler even with Admin rights and the settings I provided above. All I am trying to do is upload a 50 mb file nightly. This machine does not even have AV. It did have Kaspersky on it but we took it off.

I truly appreciate all that you guys do in helping the masses. Any other thoughts or suggestions are appreciated.

FTPUpload-GeneralTab.png
FTP-EventTab.png
FTp-Actions.png
FTP-ActionChanges.png
0
 
Fletcher BurdineTableau Trainer & Consultant Sales Exec.Author Commented:
Here is what I get when I go from the Client machine and click on the batch file that attempts to upload the file to FTP. Does anyone know what is stopping this.


WhenBatchisClickedByUserFromClie.png
0
 
BillDLConnect With a Mentor Commented:
Hi ruavol2

Most often there should be no difference in behaviour between a batch file with a *.BAT extension and one with a *.CMD extension.

As far as I understand it, there should really be no differences in behaviour of a batch file with the *.BAT or *.CMD extension when executed directly or from a shortcut on Windows XP and later (and probably also 2000).  As far as I'm aware it's like the difference between Regedit.exe and Regedt32.exe on a Windows XP system.  The latter just redirects to Regedit.  I'm sure that even if you open Command.com on an "NT" based system and run a command, processing is redirected to CMD.exe.  So my understanding is that CMD.EXE executes all batch files on more recent Windows systems.  One way to test whether it is running the 16-bit Command.com or the 32-bit CMD.exe is to echo the %ComSpec% variable at the start of the batch file.

I did, however, once save out the following demonstration batch file from a source that I never noted that behaves differently for some reason that I never took time to figure out when named as a *.BAT and a *.CMD file.

@echo off&setlocal ENABLEEXTENSIONS
call :func&&echo/I'm a cmd||echo/I'm a bat
goto :EOF

:func
md;2>nul
set var=1

The following section in the Wikipedia page appears to describe some differences also (sorry, but I haven't read them all to see what they are):
http://en.wikipedia.org/wiki/Batch_file#Differences

This MAY also be relevant:
"Cmd.exe does not support UNC names as the current directory":
http://support.microsoft.com/?kbid=156276
From the description and solution is clearly relates to Windows NT, but it is inferred from the "Applies To" section that Windows 2000 and XP may also be affected.  I don't think that is correct though.

Here is a very lengthy page about the Windows Command Shell that you may have the time to read:
http://technet.microsoft.com/en-us/library/cc723564.aspx

Be aware that if you have 3 files of the same name in one folder, but with different extensions, when called from the command line without the extension, the first program to be selected and run is defined in the order of the PATHEXT environment variable.

Bill
0
 
Fletcher BurdineTableau Trainer & Consultant Sales Exec.Author Commented:
I have not been able to test this yet. Currently I have not seen anything that was given as a solution and actually works. I am going back through every detail as I can and retrying everything. If not I am going to have to pay someone to do this. I have posted this question 3 different ways on EE and none of the solutions have worked. I have even had conflicting messages from Experts saying it cannot be done and others saying the code will work. None of the exact codes (and they are exact codes) have worked.
0
 
Fletcher BurdineTableau Trainer & Consultant Sales Exec.Author Commented:
I have not proven that any of these work yet completely but they do partially. Based on the conflicting statements I am a bit confused. However I feel there is enough good content to prove one of them is correct in certain circumstances or the right situation. The content is exceptional and well documented. SO I feel I have to give some credit to those that participated. Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.