Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Trying to execute FTP batch file

Status
Not open for further replies.

azziuhc

Programmer
Apr 29, 2010
26
US
I am trying to execute a command to transfer data file within SQL job agent using FTP
I have created a dos batch file called ftp2site.scr:
--ftp2site.scr:
REM -- BEGIN BATCH File
@echo off
open 216.22.1.333
mylogin
mypass
cd /user/download
put "CustDataFile.xls"
bye
REM -- End OF FIle

FTP works ok using Dos compand
C:>ftp -s:ftp2site.scr

However I am trying to execute this command within SQL2005
exec master.dbo.xp_cmdshell 'ftp -s:c:\temp\ftp2site.scr'

I am getting an error that it cannot find the file.
Any thought, Examples or hints how can I ftp the files.
Thank you
 
If your server is not on your computer then C: drive is not yours.

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Thank you for your quick answer.
I am logged in on the server itself as administrator
C: is the server Hard drive.

Please advice
Thank you
 
is ftp2site.scr in the TEMP dircectory or is it in the ROOT.

Your working example is in the root unless TEMP is in your path.

Simi
 
simian336:
Thank you for your response
Yes I should made it clear (becuase I copied in the root and the temp folder)

c:\Temp>ftp -s:ftp2site.scr
SQL:
master.dbo.xp_cmdshell 'ftp -s:c:\temp\ftp2site.scr'
Please advice
Thank you
 
There have been situatuions where I have had to put the program call into a batch file, then call the batch file instead.

test.bat
ftp -s:c:\temp\ftp2site.scr

exec master.dbo.xp_cmdshell 'C:\temp\test.bat'

Simi
 
Thank you
yes the batch file worked perfectly fine.

Also an add on:
I was remotely logged in to the server.
C: was my local PC instead of my remote drive.
I realized I had to go to my remote and from there access the C: drive. (That was resulting my error of not finding the file)
regards :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top