Question

FTP in Batch File not working with Windows Task Scheduler

Asked by: ruavol2


Here is the Batch file for the FTP:
Called - BATCH-FTP_SCATDB_DATA.bat

@echo off
(echo open ??.??.??.??
echo user MyUser
echo MyPassword
echo cd /Backup_DataFolder
echo bin
echo put "C:\Users\Public\ServerDataBackup\SRSCDataBackup.7z"
echo quit
) | ftp -n -s -i

When I used the Windows Task Scheduler I put in this:
Action: Start a Program
Program/Script: ftp
Add Arguments: -n -s:"C:\Users\BatchFolder\Documents\BATCH-FTP_SCATDB_DATA.bat"

I have checked with my Hosting provider and they say I have access. I can use Filezilla and upload the files from the same server directly to the FTP site manually with no problem. It seems to show something under Permissions when I try to upload using Windows FTP Under
Filezilla it says Owner/Group "ftp/ftp" the permissions said rw-r-r. I do not know if that is an issue or not since I can manually upload.
I did notice before I put the "-n" in this statement of the last line in the batch file  " ftp -n -s -i " that the file " SRSCDataBackup.7z " did get placed in the folder but it had only 0 kb and I waited 15 minutes to see if it had fully uploaded. It did not. Any help you could provide is much appreciated.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-27 at 05:10:58ID24846896
Tags

FTP Batch file using Windows Task Scheduler in Windows 2008 Server

Topics

Windows Batch Scripting

,

FTP Software

,

Windows 2003 Server

Participating Experts
3
Points
500
Comments
32

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. FileZilla FTP
    Has anyone used FileZilla FTP Server? I'm trying to use it, but having trouble connecting to it, both internally and externally. I've configured the Linksys router to forward port 20 and 21, enabled FTP port 21 in the Windows firewall, and set the external IP and custom ports...
  2. Filezilla Server sftp or psftp
    Has anyone been able to successfully get a Filezilla server setup properly with sftp or psftp on the client side. Current setup Filezilla Server (unknown version) as Server on Windows I would like to use sftp or psftp (0.6 version of Putty's SFTP), but I can't seem to ge...
  3. how to setup filezilla to utodownload
    Have a costumer that has to connect to an ftp server everyday and downlaod some folder and files, he has been doing it manually vis explorer until last week I set up filezilla for him and he's been doing it via filezilla now. Is there a way to setup filezilla to check everyd...
  4. Cannot FTPS to FileZilla
    Hi All, I have a .net C# app that uses IP*Works!SSL V8 version 8.1.3750.0 (from /n software Inc.) to transfer files to a ftp server. It works correctly with Serv-U server however I cannot ftps to a Filezilla server. In more details, Filezilla accepts the ssl connection and st...
  5. FileZilla FTP Server
    Has anyone managed to install FileZilla FTP server on a Windows Server 2008 R2 machine, or is it possible or not to do so ?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: wallyvanPosted on 2009-10-27 at 05:25:24ID: 25671573

try to switch to binary mode.

Add the following line :
echo binary

 

by: ruavol2Posted on 2009-10-27 at 05:54:48ID: 25671811

Where do I put that? I know little about Batch files someone helped me with this code.

 

by: ruavol2Posted on 2009-10-27 at 06:23:00ID: 25672077

Also I noticed that when I go to the Batch file and I right on the Batch file I notice the cmd.exe window pops up and inside the black window the word "Password:_" comes up. The cursor is not blinking. I also try to type in a password that I believe to be relevant and nothing happens. No characters move the cursor or show asterisk. Any thoughts as to why that is happening?

 

by: farhankaziPosted on 2009-10-27 at 06:55:39ID: 25672423

Try following batch script if this works for you!

@ECHO OFF
(	ECHO OPEN ??.??.??.??
	ECHO UserName
	ECHO Password
	ECHO CD /Backup_DataFolder
	ECHO BINARY
	ECHO SEND "C:\Users\Public\ServerDataBackup\SRSCDataBackup.7z"
	ECHO QUIT)>Config.ftp
 
FTP -s:Config.ftp

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

Select allOpen in new window

 

by: ruavol2Posted on 2009-10-27 at 07:07:32ID: 25672557

I tried that and no difference? The file is about 40 mb that I am trying to upload. Do you have any other ideas? What about my commands in the Task Scheduler are they correct?

 

by: farhankaziPosted on 2009-10-27 at 07:15:58ID: 25672644

Try to execute the script from command line? If this uploads the data then their must be something wrong with scheduled tasks job properties.
Make sure "Run" points to the script file (including path) and "Start in" points to the folder where the the script resides.
Like shown in attached picture:

 

by: ruavol2Posted on 2009-10-27 at 09:53:00ID: 25674668

Still not working. Farhankazi You can see from the question that the last line for me is
Echo QUIT
ftp -n -s -i

You have this:
ECHO QUIT)>Config.ftp
FTP -s:Config.ftp

I don't have what you have. Can you clarify the config.ftp with an example.

When I click Run on the task it shows that it runs with no errors within a few seconds. The actuall upload manually takes at least 3 minutes not 3 seconds. Wwhen I go to the FTP to verify the file is not there. Do you see any problems with my code?

 

by: farhankaziPosted on 2009-10-27 at 10:36:08ID: 25675148

I am unable to run your mentioned script from command line. It gives FTP command help instead of transferring file.
Did you try to run my script from command line?
Please try again by replacing following line:

ECHO CD /Backup_DataFolder
with
ECHO CD Backup_DataFolder/

If it works from command line, then run through scheduled tasks and post the "Result Code" and Log file. (Scheduled Tasks -> Advanced -> View Log).

 

by: ruavol2Posted on 2009-10-27 at 11:17:45ID: 25675645

I tried the ECHO CD Backup_DataFolder/  change.
I ran the Task and it ran very quickly. It should take at least 3-4 minutes. Here is the screen shot. let me know if you need more.
Also could a space between the characters in the folder "Batch Folder\" make a difference?

Action: Start a Program
Program/Script: ftp
Add Arguments: -n -s:"C:\Users\Batch Folder\Documents\BATCH-FTP_SCATDB_DATA.bat"

Just wondered as I actually used my folder containing my user name which has a space between?

here are the results.

 

by: QlemoPosted on 2009-10-27 at 11:27:39ID: 25675744

You should not use a CMD/batch script as input for FTP. That does not make any sense. The batch file itself calls the FTP command. The task is hence

Action: Start a Program
Program: cmd.exe
Arguments: C:\Users\Batch Folder\Documents\BATCH-FTP_SCATDB_DATA.bat

Further you do not need the -s switch for FTP in the script itself. -s is for applying a file as FTP script, but you are providing the commands via pipe. This is the correct line
) | ftp -n -i

 

by: ruavol2Posted on 2009-10-27 at 12:55:21ID: 25676684

I made exactly those changes.
I am not getting any results from the batch file. I can with Filezilla manually.
for the cmd.exe do I need to full path in that as well?
Also does that mean I do not use the "  -s " anywhere in anything?
We are trying to do a nightly backup rewriting over the database from the night before.

Here is the latest result set. It looks like it is starting but nothing is getting uploaded. I am baffled? Any thoughts?

 

by: QlemoPosted on 2009-10-27 at 17:19:31ID: 25679008

When you view your Scheduled Tasks, use the Explorer to do so, and go into the last menu of Explorer. There is a menu item for the log file. Have a look at that - it should reveal more details.
The log file is written circular, that is you have to search for a ====== line, which marks the "end of file" position.

You might need to add the complete path for cmd.exe (%Systemroot%\system32\cmd.exe), but as far as I can remember that path is added automatically as soon as you save the task.

For testing, you should allow the task to act interactively (that is, it should run with your account while you are logged in). And you should add a
pause
at the very end of the batch file (after ftp call).

About -s: Yes, the way the FTP commands are provided you do not need any -s.

 

by: ruavol2Posted on 2009-10-27 at 23:17:43ID: 25680325

I am to the point where I may need to take this offline and hire someone to get this to work. I can pay  if someone can troubleshoot this. I have tried everything you have asked to the best of my knowledge.

I do not know how to add a pause in the Batch file. Something is just not working and you have all the code I am using. The Task stays hung in the Running position and nothing happens. Unless you think that the pause will do the trick after the FTP call (which I do not even know where that is). I have everything in this thread in place. I did put in the full file path on cmd.exe. I also there is no ====== line anywhere to be found.

The only thing I did not get an answer on was whether the space between my name in the folder \Rob Burdine\ would make a difference in the Action section. I changed it to a new folder with no space but there was not a difference. I have tried so many things and I have. I have all but given up. Please advise me of my options I am just about out of them.

 

by: ruavol2Posted on 2009-10-28 at 10:41:51ID: 25686035

A ha I think I am on to something. Finally can you help me with this. Before I was getting the prompt below when I simply clicked on the batch file and get the cmd.exe with the word password in it and a non-blinking cursor.

I typed in my user password and the black screen went away and dissapeared. The file got  uploaded to the FTP site but it had a file size of Zero. So what does that mean? That I have to put some kind of extra code that puts in my user login password for Windows 2008 Server in that little command window you see below.


 

by: QlemoPosted on 2009-10-28 at 11:01:10ID: 25686263

FTP creates a file of zero size on copy (get or put) if the source does not exist.

About the passowrd, you can try to combine user and password on one line - depending on the remote FTP server, this works.


@echo off
(echo open ??.??.??.??
 echo user MyUser MyPassword
 echo cd /Backup_DataFolder
 echo bin
 echo put "C:\Users\Public\ServerDataBackup\SRSCDataBackup.7z"
 echo quit
) | ftp -n -s -i

                                              
1:
2:
3:
4:
5:
6:
7:
8:

Select allOpen in new window

 

by: farhankaziPosted on 2009-10-28 at 11:12:40ID: 25686409

Minor correction... Remove -s switch from FTP statement.

@echo off
(echo open ??.??.??.??
 echo user MyUser MyPassword
 echo cd /Backup_DataFolder
 echo bin
 echo put "C:\Users\Public\ServerDataBackup\SRSCDataBackup.7z"
 echo quit
) | FTP -n -i

                                              
1:
2:
3:
4:
5:
6:
7:
8:

Select allOpen in new window

 

by: QlemoPosted on 2009-10-28 at 11:13:36ID: 25686422

Of course. Cut&Waste error ;-)

 

by: ruavol2Posted on 2009-10-28 at 12:41:50ID: 25687392

Okay once again I am confused.
DO I use "echo Bin" or "echo Binary"


Earlier you told me to switch to "echo cd Backup_SunRiver/
Now it is back to "echo cd /Backup_SunRiver
Which is it ?

echo user MyUser
echo MyPassword

Now its "echo user myuser mypassword "..................you want that right together correct ? Just a space between them. Right?

 

by: QlemoPosted on 2009-10-28 at 12:54:38ID: 25687526

echo user myuser mypassword
is correct. Only a space inbetween. MS FTP server takes that format, other FTP servers might not.

echo cd /Backup_SunRiver
is good. It will change to the folder located under the root. Without the slash, it is changing to the subfolder located under the FTP home folder, which can make a big difference.

echo bin   is the short form of  echo binary

 

by: ruavol2Posted on 2009-10-29 at 04:54:20ID: 25692595

I hate to say it but it did not work. I am posting the response to this problem that the Hosting provider said may be the problem. I do not know  if that is true or not but I thought I would put it past you guys.
The site I am uploading to is a Linux box. However I can upload with Filezilla with no problem. They say:
 
Hello Rob,  
  The issue is that batch files are a Windows convention, and while it is possible to run them on a Linux machine, all of the commands used in the .bat file must be Linux commands.
 
@echo off  
(echo open ??.??.??.??  
echo user MyUser MyPassword  
echo cd /Backup_SunRiver  
echo bin  
echo put "C:\Users\Public\ServerDataBackup\SRSCDataBackup.7z"  
echo quit  
) | ftp -n -s -i  
 
In the above script, only cd, quit, and ftp are valid commands in RedHad Linux. You may want to consider using a bash script instead. Below are some resources on bash scripting:  
 
http://en.wikipedia.org/wiki/Bash  
http://www.linuxconfig.org/Bash_scripting_Tutorial  
http://tldp.org/LDP/abs/html/  

I called them back got a different technician and he said that the guy who gave me this answer was wrong. What do you think? Remember I am sending this up from a Windows 2008 Server's Task Scheduler to at box that does happen to be a Linux box but I do not see how that would make a difference just to transfer the zipped file up via FTP? This thing just gets more interesting by the day........? !

 

by: QlemoPosted on 2009-10-29 at 14:07:00ID: 25698272

"Wrong". The commands are executed on Windows, producing an output stuffed into FTP. The text stuffed into FTP needs to be FTP convention. The only questionable FTP command is USER, all others are FTP standard.

 

by: ruavol2Posted on 2009-10-29 at 22:04:24ID: 25700271

The Hosting provider acknowledged that they were mistaken. However they checked the code and said this:

This is a 'local' issue for you and you would need to continue troubleshooting it as such.  We have verified that the FTP server on our end is configured correctly and is working as expected.  While your code may be valid, since this is on your server in an environment we are not familiar with there is little else we can do to assist in this regard.

Should I post my question to the Windows 2003 Server zone as there seems to not be a zone for Windows 2008 Server? I have exhausted what I know to do..

Unless there is something I could check on the Server that would stop the process from launching when clearly I can do the upload manually with Filezilla? Help Me Obi One your my only hope !

 

by: QlemoPosted on 2009-10-30 at 01:28:37ID: 25700941

Reading that, I come to the conclusion that you do not have the slightest touch of knowledge here. I will treat you accordingly.

On you Windows server, open a CMD prompt. Type

ftp -n
then type the commands above, without the prefixed echo. That is
open xx.xx.xx.xx
user  MyUser MyPassword  
and so on. After each line, examine the responses from the remote system. And - tell us what is not working. "It does not work" doesn't help. You need NOT to communicate with your provider, as long as we do not suspect or detect a failure on their side.

 

by: ruavol2Posted on 2009-11-02 at 14:10:00ID: 25724323

I love it ! My friend after having 23 posts you should have realized I haven't the slightest touch of knowledge here. HA HA HA! Don't get me wrong I am eternally grateful for the help.

Here is what I did I got as far as the user name password before I hit the road bump.
I got this response after the user password. The user and password seemed to have worked. I did get the message then it seems to have gone past that and got hung up on the
"echo cd /Backup_SunRiver"

331 Please specify the password.
230 Login successful.
ftp> echo cd /Backup_SunRiver
Invalid command.
ftp> echo cd /Backup_SunRiver
Invalid command.
ftp> echo cd /BackupSunRiver
Invalid command.
ftp>

I took out the " _ " underscore thinking it might be that. So far that is as far as I got. Any thoughts?

 

by: QlemoPosted on 2009-11-02 at 14:17:28ID: 25724393

Ehem. Remove the echo from each line when you type it yourself in FTP. The echo is used in the batch file, to print out the FTP command. The command itself consist of the part after echo. Hence you type:

ftp -n
open ??.??.??.??  
user MyUser MyPassword  
cd /Backup_SunRiver  
bin  
put "C:\Users\Public\ServerDataBackup\SRSCDataBackup.7z"  
quit  

 

by: ruavol2Posted on 2009-11-02 at 16:09:11ID: 25725097

Dude you must be a saint to have to deal with me. Here is what I got after I  put in the following line:
put "C:\Users\Public\ServerDataBackup\SRSCDataBackup.7z"


200 PORT command successful. Consider using PASV.
425 Failed to establish connection.
ftp>

Is this the culprit? I do not know what PASV means?

 

by: ruavol2Posted on 2009-11-03 at 09:21:45ID: 25731227

I looked up the PASV problem. One said it may be the Firewall. So I turned it off to make sure and that did not do it.
Another said to try typing Passive or PASV after the ftp> so ftp> passive or ftp> PASV and I got back an invalid command? I think we are getting close here must be something simple?

 

by: QlemoPosted on 2009-11-03 at 10:49:11ID: 25732097

Did you just type PASV, nothing else on that line?

 

by: ruavol2Posted on 2009-11-03 at 11:39:43ID: 25732659

Yes that is what the tech responses out on Google said to do? I also tried the word passive.

 

by: ruavol2Posted on 2009-11-03 at 17:21:19ID: 25735621

The line was ftp> PASV and I also tried ftp> Passive any thoughts?

 

by: ruavol2Posted on 2009-11-06 at 11:06:05ID: 25762047

I just turned on the "Show Blocked Programs" in Windows Firewall and tried running the process again. And low and behold I get a Windows Security Alert "Windows has blocked ftp.exe.

I am assuming I need to go to Windows Firewall and "Add Program" set the ftp.exe and make that an exception. I was under the impression that when FTP Server was checked under exceptions that that was the ftp.exe program being allowed access.

 

by: ruavol2Posted on 2009-11-09 at 07:42:29ID: 25776853

Yes that was it. You guys verified that everything was working and helped me elliviate several problems with the code getting hung up which I had no clue. Then when I started looking for blocked programs and removed all the virus ware and firewalls noted that Windows Firewall had FTP server allowed. I thought that was the FTP.EXE I could not tell by looking at the properties. Once I added the file everything worked well. Thank you very much.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...