Upload to FTP - Cannot bind argument to parameter ‘Path’ because it is null

I am assisting our developer with using the “Upload to FTP” step in Octopus. We referenced this article: https://library.octopus.com/step-templates/3b534e57-e8b0-4a06-aa2c-9e7eba1f4337/actiontemplate-upload-files-by-ftp

They are using a password instead of a passkey and according to the documentation:

FtpPasskey
Path to the PPK passkey file, leave blank if using a Password

Yet I am receiving this error:

Attempting to use passkey instead of password
06:32:28 Error | Cannot bind argument to parameter ‘Path’ because it is null.

More details: The developer is deploying the package to one of their dev servers, and also running the Upload to Ftp step on that server, which has WinSCP installed. Running it locally on the server works with the same settings (username, password).

Has anyone run into this before with the Octopus step?

Hey Alex,

Thanks for reaching out.

I took a look at the PowerShell code and the problem is here:

if ($FtpPasskey -ne "") {
  Write-Host "Attempting to use passkey instead of password"

  # Check key exists
  if (!(Test-Path $FtpPasskey)) {
    throw "Unable to locate passkey at: $FtpPasskey"
  }

  $sessionOptions.SshPrivateKeyPath = $FtpPasskey

  # If the key requires a passphrase to access
  if ($FtpPasskeyPhrase -ne "") {
    $sessionOptions.PrivateKeyPassphrase = $FtpPasskeyPhrase
  }
}
else {
  $sessionOptions.Password = $FtpPassword
}

I did some debugging and see that leaving the parameter blank is indeed making that parameter $null. The if check is never working like it should because its hitting on “”, not $null.

You could use this version instead, which you will not hit this error on that section (please make sure this new step template won’t interfere with your current process before implementing it by reading the code):
https://library.octopus.com/step-templates/8b316926-0821-459b-9869-3ca98fd9087e/actiontemplate-upload-files-by-ftp-from-package

Or you can locally modify the code and change it from…

if ($FtpPasskey -ne "") {

To

if (![string]::IsNullOrEmpty($FtpPasskey)) {

This should get you to that else block and use the password field instead.

Please let me know if that works for you or if you need any further assistance with this one.

Thanks,
Jeremy

Hi Jeremy,

This worked perfectly. Thank you so much for the script update!

Best,
Alex

1 Like

Hi Alex,

You’re very welcome! Thanks for letting me know it worked for you. I hope you have a great rest of your week.

Best,
Jeremy

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.