Some help with command syntax

Advertisement

davhal
Joined:
Posts:
2

Some help with command syntax

Hi All,

I am trying to embed a cmd command into a PowerShell script. The command fires up the winscp.com file and connects to the destination but then fails on the put command. I am thinking I have made a mistake with the double quotes somewhere.

I can also confirm each variable is populated and passing to the cmd command. Again it runs the open command fine with the variables embedded.
cmd.exe /c ""$ScriptDir\WinSCP.com"  /log="$ScriptDir\WinSCP.log" /loglevel=2 /command "open ftps://"$Username":"$Password"@"$FTP_URL"/"$DestinationFolder" -certificate=$SSH_FingerPrint" "put $NewCerts""
Logs simple show
Missing parameter for command 'put'.
NOTE: the script has been edited to redact sensitive information.
. 2022-11-16 13:55:13.693 Login time: Wednesday, 16 November 2022 1:55:13 PM
. 2022-11-16 13:55:13.693 --------------------------------------------------------------------------
. 2022-11-16 13:55:13.693 Script: Retrospectively logging previous script records:
> 2022-11-16 13:55:13.693 Script: open ftps://[USERNAME]:***@[IP ADDRESS]/[DESTINATION FOLDER] -certificate=$SSH_FingerPrint
> 2022-11-16 13:55:13.693 Script: Parameter: ftps://[USERNAME]:***@[IP ADDRESS]/[DESTINATION FOLDER]
> 2022-11-16 13:55:13.693 Script: Switch:    -certificate=$SSH_FingerPrint
. 2022-11-16 13:55:13.693 --------------------------------------------------------------------------
. 2022-11-16 13:55:13.693 Session name: [USERNAME]@[IP ADDRESS] (Ad-Hoc site)
. 2022-11-16 13:55:13.693 Host name: [IP ADDRESS] (Port: 990)
. 2022-11-16 13:55:13.693 User name: [USERNAME] (Password: Yes, Key file: No, Passphrase: No)
. 2022-11-16 13:55:13.693 Transfer Protocol: FTP
. 2022-11-16 13:55:13.693 Ping type: Dummy, Ping interval: 30 sec; Timeout: 15 sec
. 2022-11-16 13:55:13.693 Disable Nagle: No
. 2022-11-16 13:55:13.693 Proxy: None
. 2022-11-16 13:55:13.693 Send buffer: 262144
. 2022-11-16 13:55:13.693 UTF: Auto
. 2022-11-16 13:55:13.693 FTPS: Implicit TLS/SSL [Client certificate: No]
. 2022-11-16 13:55:13.693 FTP: Passive: Yes [Force IP: Auto]; MLSD: Auto [List all: Auto]; HOST: Auto
. 2022-11-16 13:55:13.693 Session reuse: Yes
. 2022-11-16 13:55:13.693 TLS/SSL versions: TLSv1.0-TLSv1.3
. 2022-11-16 13:55:13.693 Local directory: default, Remote directory: /appdata_students-online/pdfs, Update: Yes, Cache: Yes
. 2022-11-16 13:55:13.693 Cache directory changes: Yes, Permanent: Yes
. 2022-11-16 13:55:13.693 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2022-11-16 13:55:13.693 Timezone offset: 0h 0m
. 2022-11-16 13:55:13.693 --------------------------------------------------------------------------
< 2022-11-16 13:55:13.709 Script: Connecting to [IP ADDRESS]:990 ...
. 2022-11-16 13:55:13.709 Connecting to [IP ADDRESS]:990 ...
. 2022-11-16 13:55:13.709 Connected
. 2022-11-16 13:55:13.709 TLS layer changed state from unconnected to connecting
. 2022-11-16 13:55:13.724 TLS layer changed state from connecting to connected
. 2022-11-16 13:55:13.724 Connected with [IP ADDRESS]:990, negotiating TLS connection...
. 2022-11-16 13:55:13.758 TLS connect: SSLv3/TLS write client hello
. 2022-11-16 13:55:13.758 TLS connect: SSLv3/TLS read server hello
. 2022-11-16 13:55:13.758 TLS connect: SSLv3/TLS read server certificate
. 2022-11-16 13:55:13.758 TLS connect: SSLv3/TLS read server key exchange
. 2022-11-16 13:55:13.758 TLS connect: SSLv3/TLS read server done
. 2022-11-16 13:55:13.773 TLS connect: SSLv3/TLS write client key exchange
. 2022-11-16 13:55:13.773 TLS connect: SSLv3/TLS write change cipher spec
. 2022-11-16 13:55:13.773 TLS connect: SSLv3/TLS write finished
. 2022-11-16 13:55:13.787 TLS connect: SSLv3/TLS write finished
. 2022-11-16 13:55:13.787 TLS connect: SSLv3/TLS read change cipher spec
. 2022-11-16 13:55:13.787 TLS connect: SSLv3/TLS read finished
. 2022-11-16 13:55:13.787 Verifying certificate for "" with fingerprint [FINGERPRINT] and 18 failures
. 2022-11-16 13:55:13.787 Certificate for "" matches cached fingerprint and failures
. 2022-11-16 13:55:13.787 Using TLSv1.2, cipher TLSv1.2: ECDHE-RSA-AES256-GCM-SHA384, 2048 bit RSA, ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH     Au=RSA  Enc=AESGCM(256) Mac=AEAD
< 2022-11-16 13:55:13.787 Script: TLS connection established. Waiting for welcome message...
. 2022-11-16 13:55:13.787 TLS connection established. Waiting for welcome message...
. 2022-11-16 13:55:13.787 Read 27 bytes
< 2022-11-16 13:55:13.787 220 Microsoft FTP Service
> 2022-11-16 13:55:13.787 USER ftpupload
. 2022-11-16 13:55:13.818 Read 23 bytes
< 2022-11-16 13:55:13.818 331 Password required
> 2022-11-16 13:55:13.818 PASS ********************
. 2022-11-16 13:55:13.849 Read 21 bytes
< 2022-11-16 13:55:13.849 230 User logged in.
> 2022-11-16 13:55:13.849 SYST
. 2022-11-16 13:55:13.858 Read 16 bytes
. 2022-11-16 13:55:13.858 The server is probably running Windows, assuming that directory listing timestamps are affected by DST.
< 2022-11-16 13:55:13.858 215 Windows_NT
> 2022-11-16 13:55:13.858 FEAT
. 2022-11-16 13:55:13.881 Read 34 bytes
< 2022-11-16 13:55:13.881 211-Extended features supported:
. 2022-11-16 13:55:13.881 Read 18 bytes
< 2022-11-16 13:55:13.881  LANG EN*
< 2022-11-16 13:55:13.881  UTF8
. 2022-11-16 13:55:13.881 Read 53 bytes
< 2022-11-16 13:55:13.881  AUTH TLS;TLS-C;SSL;TLS-P;
< 2022-11-16 13:55:13.881  PBSZ
< 2022-11-16 13:55:13.881  PROT C;P;
< 2022-11-16 13:55:13.881  CCC
. 2022-11-16 13:55:13.881 Read 7 bytes
< 2022-11-16 13:55:13.881  HOST
. 2022-11-16 13:55:13.881 Read 37 bytes
< 2022-11-16 13:55:13.881  SIZE
< 2022-11-16 13:55:13.881  MDTM
< 2022-11-16 13:55:13.881  REST STREAM
< 2022-11-16 13:55:13.881 211 END
> 2022-11-16 13:55:13.881 OPTS UTF8 ON
. 2022-11-16 13:55:13.912 Read 58 bytes
< 2022-11-16 13:55:13.912 200 OPTS UTF8 command successful - UTF8 encoding now ON.
> 2022-11-16 13:55:13.912 PBSZ 0
. 2022-11-16 13:55:13.928 Read 30 bytes
< 2022-11-16 13:55:13.928 200 PBSZ command successful.
> 2022-11-16 13:55:13.928 PROT P
. 2022-11-16 13:55:13.944 Read 30 bytes
< 2022-11-16 13:55:13.944 200 PROT command successful.
< 2022-11-16 13:55:13.944 Script: Connected
. 2022-11-16 13:55:13.944 Connected
. 2022-11-16 13:55:13.944 Got reply 1 to the command 1
. 2022-11-16 13:55:13.944 --------------------------------------------------------------------------
. 2022-11-16 13:55:13.944 Using FTP protocol.
. 2022-11-16 13:55:13.958 Doing startup conversation with host.
< 2022-11-16 13:55:13.958 Script: Starting the session...
> 2022-11-16 13:55:13.958 PWD
. 2022-11-16 13:55:13.974 Read 31 bytes
< 2022-11-16 13:55:13.974 257 "/" is current directory.
. 2022-11-16 13:55:13.974 Got reply 1 to the command 16
. 2022-11-16 13:55:13.974 Changing directory to "[DESTINATION FOLDER]".
> 2022-11-16 13:55:13.974 CWD [DESTINATION FOLDER]
. 2022-11-16 13:55:13.990 Read 29 bytes
< 2022-11-16 13:55:13.990 250 CWD command successful.
. 2022-11-16 13:55:13.990 Got reply 1 to the command 16
. 2022-11-16 13:55:13.990 Getting current directory name.
> 2022-11-16 13:55:13.990 PWD
. 2022-11-16 13:55:14.022 Read 59 bytes
< 2022-11-16 13:55:14.022 257 "[DESTINATION FOLDER]" is current directory.
. 2022-11-16 13:55:14.022 Got reply 1 to the command 16
. 2022-11-16 13:55:14.022 Startup conversation with host finished.
< 2022-11-16 13:55:14.022 Script: Session started.
< 2022-11-16 13:55:14.022 Script: Active session: [1] ftpupload@10.144.120.68
. 2022-11-16 13:55:14.022 Session upkeep
> 2022-11-16 13:55:14.022 Script: put
< 2022-11-16 13:55:14.022 Script: Missing parameter for command 'put'.
. 2022-11-16 13:55:14.022 Script: Failed
. 2022-11-16 13:55:14.022 Session upkeep
. 2022-11-16 13:55:14.022 Script: Exit code: 1
. 2022-11-16 13:55:14.022 Script: Max roundtrip: 0
. 2022-11-16 13:55:14.022 Connection closed
. 2022-11-16 13:55:14.022 Got reply 1004 to the command 16
. 2022-11-16 13:55:14.022 Not waiting for complete TLS shutdown
. 2022-11-16 13:55:14.022 Disconnected from server
. 2022-11-16 13:55:14.022 Connection closed

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
38,408
Location:
Prague, Czechia

Re: Some help with command syntax

What do you need the cmd.exe there for?
This should do:
& "$ScriptDir\WinSCP.com" /log="$ScriptDir\WinSCP.log" /loglevel=2 `
  /command `
    "open ftps://$Username:$Password@$FTP_URL/$DestinationFolder -certificate=$SSH_FingerPrint" `
    "put $NewCerts" `
    "exit"
WinSCP GUI can generate such commandline for you:
https://winscp.net/eng/docs/ui_generateurl#script

Reply with quote

davhal

Re: Some help with command syntax

Thanks Martin, this worked.

I did try this approach previously but had issues with piping the $Username variable. Turns out it didn't like the : after the variable. To fix this I had to use ${Username} instead.

Reply with quote

Advertisement

You can post new topics in this forum