SFTP
Reaches Driver8's SFTP capability the same way as Kafka: a WebDriver session with
browserName: "pn5-driver8", then plain REST commands relative to that session, under the pn5-sftp/* path prefix.
File contents travel base64-encoded in the JSON body.
Status: unlike Kafka, there is currently no indirect real-world cross-check for SFTP (no equivalent continuously-running Java CI job was found at the time this was written) - the implementation is traced directly from the Java client's
RemoteSftpAgent, but has not been confirmed against a live farm from either client. If you're among the first to run this against a live farm, please report the result on DQA-122.
Usage
import { test, expect } from '@pumpo5.dev/core'
test('lists a remote directory', async ({ sftp }) => {
const entries = await sftp.list('.')
expect(Array.isArray(entries)).toBe(true)
})
The sftp fixture creates a Driver8 session before the test and closes it after, whether the test passes or fails.
Connection configuration
The sftp fixture resolves its connection details from a named profile, defaulting to SFTP. For the default
profile, values are looked up as, in order of precedence:
config.conf, under the dotted key derived from the profile name (SFTP→sftp):sftp.host="my-sftp-server"
sftp.username="myUsername"
sftp.password="myPassword"
sftp.port=22- Environment variables named
<PROFILE>_<SUFFIX>, e.g.SFTP_HOST,SFTP_USERNAME,SFTP_PASSWORD,SFTP_PORT.
host, username and password are required; port is optional. These map directly onto the Java client's
pn5:sftpHost, pn5:sftpUsername, pn5:sftpPassword and pn5:sftpPort capabilities (see
SFTP capabilities reference).
Using a different profile
Same mechanism as Kafka - override with test.use({ sftpProfile: '...' }) to read a different named profile's
config.conf/environment variables in a given test or describe block. See the equivalent section on the
Kafka page for the pattern and the caveat about
file-level test.skip() only checking the default profile.
Method reference
sftp.download(remotePath)
Returns a Buffer with the file's decoded contents.
import * as fs from 'fs/promises'
test('downloads a generated report', async ({ sftp }) => {
const contents = await sftp.download('/reports/latest.csv')
expect(contents.toString('utf-8')).toContain('orderId')
// Save it locally if the test needs to inspect it further, e.g. with a CSV parser:
await fs.writeFile('report.csv', contents)
})
sftp.upload(remotePath, contents)
contents is a Buffer or string; encoded to base64 before sending.
import * as fs from 'fs/promises'
test('uploads a test input file as a string', async ({ sftp }) => {
await sftp.upload('/incoming/test-input.csv', 'orderId,status\n123,CREATED\n')
expect(await sftp.list('/incoming')).toContain('test-input.csv')
})
test('uploads a local file as a Buffer', async ({ sftp }) => {
const fileContents = await fs.readFile('fixtures/sample.pdf')
await sftp.upload('/incoming/sample.pdf', fileContents)
})
sftp.list(remotePath)
Returns string[], the entries in the remote directory.
sftp.lstat(remotePath)
Returns the raw response value. Its shape has not been verified against a live server - treat it as opaque until confirmed.
sftp.makeDirectory(remotePath)
sftp.rename(oldRemotePath, newRemotePath)
sftp.remove(remotePath)
Removes a file.
sftp.removeDirectory(remotePath)
sftp.close()
Closes the Driver8 session. Called automatically by the fixture after the test; only call this yourself if you
created an SftpAgent directly instead of using the fixture.