-1

my text file cmdftp_put.txt contain the following:

open ftp.xxx.com 
loginxx
pwdxx
put C:\Mydatabase.bak /Sources/Mydatabase.bak 
quit 

I want to execute this file through an xp_cmdshell in order to copy the backup file from the sql server host into my ftp server.

is it possible? if yes can you tell me the syntaxe please?

Thanks a lot

1

Create a bat file that executes the Windows FTP process which reads in your cmdftp_put.txt file as input commands.

An example of the bat file (FtpBackupFile) might look like this:

@echo on
%windir%\System32\ftp.exe -s:"C:\cmdftp_put.txt"

Then use the following TSQL

exec xp_cmdshell 'c:\FtpBackupFile.bat'

The Sql Server service account will need Windows authorities to access the bat file.

|improve this answer|||||
  • Hi Scott, what does %windir%\System32\ftp. stand for? is it the path of the ftp client? does it mean that we must have an ftp client on the server where we have the backup file (sql server host)?? should I replace %windir% by the appropriate path in my case? and my last question: how can I verify if sql server service account has the required authorities? my sql server is on a virtual machine Azure. Thanks for your help – user3569267 Dec 29 '16 at 16:44
  • Scott it is ok for the path I understand what it stand for. it works!! Thanks again – user3569267 Dec 29 '16 at 16:58
0

You can just use syntax

xp_cmdshell "<path_of_the_file>\cmdftp_put.txt

But I guess you should rewrite the file. I usually use cURL to do such things (ftp put / get / etc...) Something like

<path_to_curl>\curl.exe ftp://%user%:%passwd%@%address%:%port%  -T Mydatabase.bak 
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.