[moved from StackOverflow]
We use PSFTP, along with a ppk file and a batch command file, to upload a CSV to a remote SFTP host. This has been working for many (many) months and only recently the -b parameter fails with "Fatal: unable to open"
Details:
We run PSFTP.exe on Windows using a batch file or command prompt.
The batch command file we pass with -b paramenter is called "sftpcommands.txt" and has the following lines:
put "D:\batch\Upload.csv"
quit
Here is what we run from a batch file or command prompt:
psftp.exe -v -P 22 -i D:\batch\keyfile.ppk -b D:\batch\sftpcommands.txt [email protected]
Here is the result:
Looking up host "SFTPHost.domain.com" for SSH connection
Connecting to hostIP port 22
We claim version: SSH-2.0-PuTTY_Release_0.82
Connected to hostIP (from localIP:35022)
Remote version: SSH-2.0-AWS_SFTP_1.1
Using SSH protocol version 2
No GSSAPI security context available
Doing ECDH key exchange with curve nistp256, using hash SHA-256 (SHA-NI accelerated)
Host key fingerprint is:
ssh-rsa 4096 SHA256:ajIF+morestuffhere
Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
Initialised HMAC-SHA-256 (SHA-NI accelerated) outbound MAC algorithm
Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
Initialised HMAC-SHA-256 (SHA-NI accelerated) inbound MAC algorithm
Reading key file "D:\batch\keyfile.ppk"
Using username "OurUser".
Offered public key
Offer of public key accepted
Authenticating with public key "keynameinformation here"
Sent public key signature
Access granted
Opening main session channel
Remote debug message: SFTP: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Remote debug message: SFTP: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Opened main channel
Started a shell/command
Connected to some-host.server.transfer.us-east-1.amazonaws.com
Remote working directory is /
Fatal: unable to open
Session sent command exit status 0
Main session channel closed
All channels closed
Now the strange part: we can get rid of the -b script syntax and manually enter the same commands found in the sftpcommands.txt
file when the psftp>
prompt appears (e.g.):
psftp.exe -v -P 22 -i D:\batch\keyfile.ppk [email protected]
Looking up host "SFTPHost.domain.com" for SSH connection
Connecting to hostIP port 22
We claim version: SSH-2.0-PuTTY_Release_0.82
Connected to hostIP (from localIP:35022)
Remote version: SSH-2.0-AWS_SFTP_1.1
Using SSH protocol version 2
No GSSAPI security context available
Doing ECDH key exchange with curve nistp256, using hash SHA-256 (SHA-NI accelerated)
Host key fingerprint is:
ssh-rsa 4096 SHA256:ajIF+morestuffhere
Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
Initialised HMAC-SHA-256 (SHA-NI accelerated) outbound MAC algorithm
Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
Initialised HMAC-SHA-256 (SHA-NI accelerated) inbound MAC algorithm
Reading key file "D:\batch\keyfile.ppk"
Using username "OurUser".
Offered public key
Offer of public key accepted
Authenticating with public key "keynameinformation here"
Sent public key signature
Access granted
Opening main session channel
Remote debug message: SFTP: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Remote debug message: SFTP: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Opened main channel
Started a shell/command
Connected to some-host.server.transfer.us-east-1.amazonaws.com
Remote working directory is /
psftp> put "D:\batch\Upload.csv"
local:D:\batch\Upload.csv => remote:/Upload.csv
psftp> quit
Session sent command exit status 0
Main session channel closed
All channels closed
The third party did move SFTP servers a few months back, but to my knowledge the -b parameter was still working on their new host (however I could be wrong).
To my knowledge nothing has changed on our end, and as indicated we're A/B testing with the same local logged in Windows user, same local files, etc. There should be no local rights issues as, again, we're using Windows, and the logged-on account is what is opening /editing /accessing all files involved. I've also tried moving the -b parameter into different positions in the line command.
Could this error be a security, config or format setting on the remote SFTP server causing the confusion with the -b command file?
Note: I have a ticket open with the folks operating the remote SFTP host to triangulate the issue and if I can solve this, I'll post the answer here in case it helps someone else seeing the "Fatal: unable to open" on the -b switch