Solved

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

Posted on 2007-03-29
19
2,131 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
>>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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 18

Expert Comment

by:Sham Haque
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
Maybe you could try the method described here:

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

Author Comment

by:EllsworthAdhesives
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Server Log File Space 6 33
Select2 jquery help 9 41
Company name change requiring domain change 5 60
Need Counts 11 39
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

763 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

7 Experts available now in Live!

Get 1:1 Help Now