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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help using xp_cmdshell against Linux

Status
Not open for further replies.

MKVAB

Programmer
Dec 2, 2003
86
US
I am creating a job that, if the file exists, copy it from the Linux server where it resides to a Windows server on the network.

I have been unable to determine the exact syntax of the xp_cmdshell to get into the Linux server and grab the file.

Here are a couple things I've tried:
Code:
EXEC master..xp_cmdshell  "'copy \\LinuxServName\dir1\dir2\FileName /U 'username' /P 'password' \\LocalSrvName\LocalFileName'"

EXEC master..xp_cmdshell 'copy "'\\LinuxServName\dir1\dir2\file' /U 'username' /P 'password'  \\LocalSrvName\LocalFileName'


I don't know the syntax for adding a username and password to the xp_cmdshell command. Oh, and the command I would be using with xp_cmdshell is "copy", right?

Any help is MUCH appreciated!

-MK
 
We got it figured out.
Here is how I grabbing the file from the Linux server:

1. downloaded pscp - an SCP client, command-line secure file copy utility (utilizes SSH)

2. Install the pscp.exe in the System32 directory on the SQL Server machine.

3. pass this command to the xp_cmdshell:

Code:
pscp -pw [password] [username]@[IP Address]:/dir1/dir2/file1.dat c:/dir1/file1.dat

So you should have:
Code:
EXEC master..xp_cmdshell 'pscp -pw [password] [username]@[IP Address]:/dir1/dir2/file1.dat c:/dir1/file1.dat, no_output

Note: after you download and save pscp.exe into the System32 directory, you will need to manually run the pscp utility from the command line once because you have to manually accept the registration during first use.

What a wonderful utility!

MK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top