How do I connect and download in single command line in SQL – SFTP

Advertisement

idkbs
Joined:
Posts:
2

How do I connect and download in single command line in SQL – SFTP

Hi ,
new to WinSCP – been tasked with converting a file download command to SFTP.
The previous command was on FTP and works well however we need now to transition to SFTP.
The problem I have is the SFTP command I designed seems to have a syntax error which I cannot put my finger on. The error is
Too many parameters for command 'open'.
The existing FTP job does the connection and file download in one go which is how I want to keep as well when I do the job in SFTP.

What I have done is to take this previous command of FTP, and modified it to suit the SFTP.
The only differences are that I have to additionally supply hostkey in the command (and the SFTP address and the port are different but they were just changes).
Below is the old command and the new command.

Additional info, this command is run from within SQL Server stored procedure. However I don't think it matters as I get the same error message from command-line itself from windows.

FTP script (working)
pushd \\myserver\ftp\Wnscpfolder & winscp.com /command "open ftp://userid:Password@ftp2.company.com:21/Prod/Outbound" "get *.xml ""\\myserver\FTP\inbound\""" "exit"
Sftp script (not working)
pushd \\myserver\ftp\Wnscpfolder & winscp.com /command "open sftp:// userid:Password @sftp.company.com:22 -hostkey=""ecdsa-sha2-nbvf384 384 lkiyShgtreALXcfRBQRYyWdbjpokjy5/38ZOhyx/xds="" /Prod/Outbound" "get *.xml ""\\myserver\FTP\inbound\""" "exit"

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,454
Location:
Prague, Czechia

Re: How do I connect and download in single command line in SQL – SFTP

There should be no space after the sftp:// and Password (the same way there where no such spaces in the FTP script).
Additionally, the /Prod/Outbound should be part of the session URL.
Also the port 22 is the default SFTP port, you do not need to specify it – neither you needed to specify port 21 with FTP.
"open sftp://userid:Password@sftp.company.com/Prod/Outbound -hostkey=""..."""

Reply with quote

idkbs

Re: How do I connect and download in single command line in SQL – SFTP

Hi Thank you for replying. The /Prod/Outbound in the wrong place was the culprit (I typed in a space after the password in the forum when removing the actual passwords etc).
Thanks again.

Reply with quote

Advertisement

You can post new topics in this forum