I'm attempting a cfftp to an SFTP server as follow...
# lucee
t
I'm attempting a cfftp to an SFTP server as follows:
Copy code
var ftpService = new ftp(); 
		ftpService.setServer(ftpHost); 
		ftpService.setUsername(ftpUser); 
		ftpService.setKey(ftpSSHKey);
		ftpService.setSecure(true);
		ftpService.setStopOnError(true); 
		ftpService.setPassive(true); 
		// Open connection 

		ftpService.open(); 

		try{
			ftpService.putfile(
				name="upload",
				localFile=filename, 
				remoteFile=filename,
				transferMode="auto"
			);
		} catch( any e ){
			sleep(1000);
			ftpService.putfile(
				name="upload",
				localFile=filename, 
				remoteFile=filename,
				transferMode="auto",
				passive=false
			);
		}
		ftpService.close();
I've verified that using SSH works to the server using the user & key but getting this error
Copy code
ERROR (5.5.2+00578)

com.jcraft.jsch.JSchException: invalid privatekey: [B@44ab30a5
  caused by: java.io.IOException
  com.jcraft.jsch.JSchException: invalid privatekey: [B@44ab30a5
    caused by: com.jcraft.jsch.JSchException
    invalid privatekey: [B@44ab30a5
Failing on
ftpService_._open();
I suspect I'm missing something in the ftpService settings, just not sure what.
b
What does the
ftpSSHKey
variable contain?
A file path? The actual key? PEM format? Binary?
I've only used sftp once, but I read the key from a file into the variable and the file was in the format
Copy code
-----BEGIN RSA PRIVATE KEY-----
<BASE64 ENCODED KEY HERE ACROSS MULTIPLE LINES>
-----END RSA PRIVATE KEY-----
The error message tells me Java is getting a Byte array and not a string
Copy code
invalid privatekey: [B@44ab30a5
The
[B
means a byte array
Try feeding in the PEM-encoded key as I showed above into that variable
@Travis
t
The
ftpSSHKey
contains the key's file path
b
And the format of the file?
t
Copy code
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEAswIJEKuNMrwMIz1AwR5ILVw998/gH0ajrTXIdCNSHQ8EZ8amc5fn
etc.
b
There's a good chance it needs to be in RSA format and not openssh
I've had a lot of issues with that and the Jsch libs in Java
The jGit lib in CommandBox uses Jsch for Git cloning and I've always had to use RSA keys for that to work
t
Fair enough. I'll give that a go
And thanks!
👍 1
I confirmed this is an RSA key, just no idea how to generate one that starts with
-----BEGIN RSA PRIVATE KEY-----
Tried nearly every combo with puttygen.
Well... I think I may have found it.