Link to home
Start Free TrialLog in
Avatar of RUA Volunteer2?
RUA Volunteer2?Flag for United States of America

asked on

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.
SOLUTION
Avatar of richardcardin
richardcardin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You'll need to assign administrator rights to the account that will be performing this upload. domain\user
Make sure the account being used also has the appropriate rights to the scheduled task itself.
Avatar of RUA Volunteer2?

ASKER

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
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.
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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

Avatar of Tomas Helgi Johannsson
      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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...
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 :)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.