Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

danis

Sorry - my fault!

I forgot to add the second " in the hostkey! :oops:

Thank you for your help, problem solved!
danis

Hi prikryl,

I changed my PowerShell Script.
The connection works but the rest of the script got an error. Please find here the log:

. 2012-02-23 10:59:19.118 --------------------------------------------------------------------------
. 2012-02-23 10:59:19.118 WinSCP Version 4.3.6 (Build 1655) (OS 6.1.7601 Service Pack 1)
. 2012-02-23 10:59:19.118 Configuration: HKEY_CURRENT_USER\Software\Martin Prikryl\WinSCP 2\
. 2012-02-23 10:59:19.118 Local account: Domain\sreviceuser
. 2012-02-23 10:59:19.118 Login time: Donnerstag, 23. Februar 2012 10:59:19
. 2012-02-23 10:59:19.118 --------------------------------------------------------------------------
. 2012-02-23 10:59:19.118 Session name: user@server (Ad-Hoc session)
. 2012-02-23 10:59:19.118 Host name: server (Port: 22)
. 2012-02-23 10:59:19.118 User name: user (Password: No, Key file: Yes)
. 2012-02-23 10:59:19.118 Tunnel: No
. 2012-02-23 10:59:19.118 Transfer Protocol: SFTP
. 2012-02-23 10:59:19.118 Ping type: -, Ping interval: 30 sec; Timeout: 15 sec
. 2012-02-23 10:59:19.118 Proxy: none
. 2012-02-23 10:59:19.118 SSH protocol version: 2; Compression: No
. 2012-02-23 10:59:19.118 Bypass authentication: No
. 2012-02-23 10:59:19.118 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
. 2012-02-23 10:59:19.118 Ciphers: aes,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2012-02-23 10:59:19.118 SSH Bugs: -,-,-,-,-,-,-,-,-
. 2012-02-23 10:59:19.118 SFTP Bugs: -,-
. 2012-02-23 10:59:19.118 Return code variable: Autodetect; Lookup user groups: Yes
. 2012-02-23 10:59:19.118 Shell: default
. 2012-02-23 10:59:19.118 EOL: 0, UTF: 2
. 2012-02-23 10:59:19.118 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes
. 2012-02-23 10:59:19.118 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2012-02-23 10:59:19.118 Local directory: default, Remote directory: home, Update: No, Cache: Yes
. 2012-02-23 10:59:19.118 Cache directory changes: Yes, Permanent: Yes
. 2012-02-23 10:59:19.118 DST mode: 1
. 2012-02-23 10:59:19.118 --------------------------------------------------------------------------
. 2012-02-23 10:59:19.118 Looking up host "server"
. 2012-02-23 10:59:19.134 Connecting to 192.168.1.1 port 22
. 2012-02-23 10:59:19.150 Server version: SSH-2.0-WS_FTP-SSH_7.5.1
. 2012-02-23 10:59:19.150 Using SSH protocol version 2
. 2012-02-23 10:59:19.150 We claim version: SSH-2.0-WinSCP_release_4.3.6
. 2012-02-23 10:59:19.150 Using Diffie-Hellman with standard group "group14"
. 2012-02-23 10:59:19.150 Doing Diffie-Hellman key exchange with hash SHA-1
. 2012-02-23 10:59:19.524 Host key fingerprint is:
. 2012-02-23 10:59:19.524 ssh-rsa 1024 38:9c:d5:da:b1:d3:dc:3f:46:42:40:f9:75:ca:7e:f0
. 2012-02-23 10:59:19.524 Initialised AES-256 CBC client->server encryption
. 2012-02-23 10:59:19.524 Initialised HMAC-SHA1 client->server MAC algorithm
. 2012-02-23 10:59:19.524 Initialised AES-256 CBC server->client encryption
. 2012-02-23 10:59:19.524 Initialised HMAC-SHA1 server->client MAC algorithm
. 2012-02-23 10:59:19.540 Reading private key file "C:\Scripts\FTPTransfer\keyfile.ppk"
! 2012-02-23 10:59:19.540 Using username "user".
. 2012-02-23 10:59:19.961 Offered public key
. 2012-02-23 10:59:20.756 Offer of public key accepted
! 2012-02-23 10:59:20.756 Authenticating with public key "imported-openssh-key"
. 2012-02-23 10:59:20.788 Sent public key signature
. 2012-02-23 10:59:21.536 Access granted
. 2012-02-23 10:59:21.552 Opened channel for session
. 2012-02-23 10:59:21.942 Started a shell/command
. 2012-02-23 10:59:21.942 --------------------------------------------------------------------------
. 2012-02-23 10:59:21.942 Using SFTP protocol.
. 2012-02-23 10:59:21.942 Doing startup conversation with host.
> 2012-02-23 10:59:21.942 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2012-02-23 10:59:21.942 Type: SSH_FXP_VERSION, Size: 5, Number: -1
. 2012-02-23 10:59:21.942 SFTP version 4 negotiated.
. 2012-02-23 10:59:21.942 We will use UTF-8 strings when appropriate
. 2012-02-23 10:59:21.942 Getting current directory name.
. 2012-02-23 10:59:21.942 Getting real path for '.'
> 2012-02-23 10:59:21.942 Type: SSH_FXP_REALPATH, Size: 10, Number: 16
< 2012-02-23 10:59:22.535 Type: SSH_FXP_NAME, Size: 28, Number: 16
. 2012-02-23 10:59:22.535 Real path is '/home'
. 2012-02-23 10:59:22.535 Startup conversation with host finished.
< 2012-02-23 10:59:22.535 Script: Active session: [1] user@server
> 2012-02-23 10:59:22.535 Script: 1024
. 2012-02-23 10:59:22.535 Script: Failed
. 2012-02-23 10:59:22.535 Closing connection.
. 2012-02-23 10:59:22.535 Sending special code: 12
. 2012-02-23 10:59:22.535 Sent EOF message


I just rimmed out the Username and Servername.
It seems, that it stil got probmes with the hostkey.

> 2012-02-23 10:59:22.535 Script: 1024


EDIT:

Forgot to show you how the command text looks like:

"option batch abort" "option confirm off" "open sftp://user@server -privatekey=C:\Scripts\FTPTransfer\keyfile.ppk -hostkey="ssh-rsa 1024 38:9c:d5:da:b1:d3:dc:3f:46:42:40:f9:75:ca:7e:f0"" "cd /home/from" "option transfer binary" "get -delete * C:\Scripts\Temp\" close exit
martin

Ok, I've though you are writting the command to a file.
If you case, you need to enclose every command into double quotes.
.\WinSCP.com /log=C:\Scripts\LogWINSCP.txt /command "option batch abort" "option confirm off" "open sftp://user@server -privatekey=C:\Scripts\FTPTransfer\keyfile.ppk -hostkey=""ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx""" "cd /folger/subfolder" "option transfer binary" "get -delete * C:\Scripts\Temp\" close exit


https://winscp.net/eng/docs/commandline#scripting
danis

Hi prikryl,
do I have to?

I am starting the script with this line:

.\WinSCP.com /command $script /log=$ScriptFolder\LogWINSCP.txt


That means I am directly writing the %script to the /command.

In real it would look like:

.\WinSCP.com /command option batch abort option confirm off open sftp://user@server -privatekey=C:\Scripts\FTPTransfer\keyfile.ppk -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" cd /folger/subfolder option transfer binary get -delete * C:\Scripts\Temp\ close exit /log=C:\Scripts\LogWINSCP.txt
martin

Re: Unknown Command on automation with PowerScript

Looks like you are not adding newlines after every command.
danis

[SOLVED] Unknown Command on automation with PowerScript

Hi Guys,
I have created a PowerShell Script which automatically downloads files from a FTP Server.
The connection has to be a SFTP Connection with a Private Key.
That's why I am using WinSCP - thanks for this great piece of software!

Now I'm getting the following error and I have no idea to rid it of..
My code looks like this (just a small part..):

$Script += "open sftp://$username@$FTPServer -privatekey=$PPKfile -hostkey=$SFTPFingerprint"


As you can see I'm adding some text with vaiables to the Array $Script.
Because the $SFTPFingerprint contains spaces I am defining the variable as following:

$SFTPFingerprint = '"ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"'


When I am writing the array to a text file I receive the following result:

option batch abort option confirm off open sftp://user@server -privatekey=C:\Scripts\FTPTransfer\keyfile.ppk -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" cd /folger/subfolder option transfer binary get -delete * C:\Scripts\Temp\ close exit


Now I receive this error message: Unknown command '1024'.
Afer searching the forums I found a Link to this ticket: https://winscp.net/tracker/494

Does somebody got an idea?