Solved

FTP via SQL Server DTS and cmdshell- can't get it to work!!! 500pts.

Posted on 2007-03-29
19
2,135 Views
Last Modified: 2013-11-30
Hi all,

I tried using the following code to automate an ftp upload:

exec master.dbo.xp_cmdshell 'cd D:\inetpub\ & ftp -s:froogle.txt "www.mysite.com " & [myFTPusername] & [myFTPpassword] '

I cannot get the DTS package to execute this ftp task- nothing fails (no errors), but when I check my ftp site, the file never gets there.

Your help is greatly appreciated,


colin
0
Comment
Question by:EllsworthAdhesives
  • 7
  • 7
  • 2
  • +3
19 Comments
 
LVL 16

Assisted Solution

by:rboyd56
rboyd56 earned 50 total points
ID: 18817281
Have you tried putting this in a CMD file and calling the CMD file from a execute process task.

0
 
LVL 21

Expert Comment

by:Kevin3NF
ID: 18818181
This would be simpler to create a one task package - ftp task and then schedule that...or am I missing a detail?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18818528
The following questions are now considered abandoned, please attend to them:
1 02/15/2007 500 ASP.NET 2.0, Session State (an... Open Windows OS ...
2 01/30/2007 500 ASP.NET DetailView won't hide ... Open ASP.Net Programm...
3 01/17/2007 500 MySQL help for ASP.NET.....why... Open MySQL
0
 

Author Comment

by:EllsworthAdhesives
ID: 18819068
acperkins- I have cleaned them up. Can't you send a message to my account? Or is posting on one of my questions the only way to notify me of something like this? If so, please send to my account if there is a next time.

Thanks,

colin
0
 

Author Comment

by:EllsworthAdhesives
ID: 18819123
SQL Server 2000 FTP task only allows for incoming files from external sites, or transfer of files between directories on the same CPU (not uploads to sites, whyich is what I need). At least that's what the menu options led me to believe- that's why I am using cmdshell.
0
 

Author Comment

by:EllsworthAdhesives
ID: 18819145
rboyd56: could you provide me an example of how I would do this (is it as easy as saving to a .txt, changing the extension to .cmd......and then, actually I don't know what I would do next (call the file).  An example would be awesome if you could show me.

Thanks
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18820179
>>Can't you send a message to my account?<<
I am afraid not.  I am just a member of this community like yourself.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18820197
>>SQL Server 2000 FTP task only allows for incoming files from external sites<<
I don't believe anyone is suggesting you use the FTP Task to upload (and you are correct it cannot be done).  Rather they are suggesting you add an "Execute Process Task" which executes ftp.exe with the script.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18820215
P.S.  The reason the line:
exec master.dbo.xp_cmdshell 'cd D:\inetpub\ & ftp -s:froogle.txt "www.mysite.com " & [myFTPusername] & [myFTPpassword] '
Is failing is because you are attempting to change folders AND execute in the same line.  This cannot be done.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 18

Expert Comment

by:Sham Haque
ID: 18822065
Create a  batch file to do what you need, then call that from xp_cmdshell:
eg.

cd D:\inetpub
ftp -s:froogle.txt "www.mysite.com " [myFTPusername] [myFTPpassword]
0
 

Author Comment

by:EllsworthAdhesives
ID: 18826190
darnit all! I did what you suggested gbshahaq but I get nothing. I tried executing the command manually from cmd prompt and just got all the ftp options- nothing happened. I looked all over the net and the above is the only script I could find to automate an ftp upload- is there something missing, out of place, or what can I check to find out why this isn't executing?

The username and password are definately correct, as is the filename and location. I don't know what else I can do? All suggestions are greatly appreciated.

Thanks!
0
 

Author Comment

by:EllsworthAdhesives
ID: 18826207
Oh and, acprekins- I understand about your other comment on my open questions. I just thought you were a moderator and though there must be another way of telling me that (esp. with this great new redesign of EE).

As for the automated ftp upload from SQL Server DTS via xp_cmdshell executing a bat with the above format- I still can't get it to work...
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18827389
>>I tried executing the command manually from cmd prompt and just got all the ftp options- nothing happened.<<
That is because username and password are not valid parameters for ftp.exe.  They are usually included in the ftp script.  To see all the valid arguments you can use from the command line, use this:
FTP -?
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 100 total points
ID: 18827411
Your script should look like this:
[Your FTP user name]
[Your FTP password]
put [full path name to your file]
bye

You then call it as follows:
ftp -s:[full path name to the script file] [host name]
0
 
LVL 11

Expert Comment

by:dready
ID: 18829876
Maybe you could try the method described here:

http://www.nigelrivett.net/s_ftp_PutFile.html
0
 

Author Comment

by:EllsworthAdhesives
ID: 18837113
Hi again,

Thanks for your input- I followed your suggestion, modified my script, and executed the SQL stament below, however, I still cannot get the file to go anywhere.. Do I have syntax incorrect?


exec master.dbo.xp_cmdshell  'ftp -s:D:\inetpub\ftp_upload.bat www.mysite.org'
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18840845
What happens when you execute the following from the command line:
ftp -s:D:\inetpub\ftp_upload.bat www.mysite.org
0
 
LVL 18

Accepted Solution

by:
Sham Haque earned 350 total points
ID: 18841688
you should be calling the bat file with no parameters....

1. you have a ftp script file saved as D:\inetpub\froogle.txt containing the following lines:

[Your FTP user name]
[Your FTP password]
put [full path name to your file]
bye

2. you have a batch file saved as D:\inetpub\ftp_upload.bat containing the following lines:
cd D:\inetpub
ftp -s:D:\inetpub\froogle.txt "www.mysite.org"

3. you call the batch file from the command line (to test as acperkins suggested) or from the xp_cmdshell proc.

exec master.dbo.xp_cmdshell 'D:\inetpub\ftp_upload.bat'




0
 

Author Comment

by:EllsworthAdhesives
ID: 18843411
gbshahaq: Thank you so much- you're explaination was concise, complete, and got everything working, perfectly. Thanks to everyone else who helped out- I understand batch execution much better now and can have this run as a scheduled job on one of my SQL Servers.

Thanks again to all!! You were a great help.

-colin
0

Featured Post

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now