SFTP delivery

For arlanix/product-feed 1.0.0

SFTP delivery

The SFTP channel uploads a feed to an SFTP server instead of, or as well as, publishing it on the store. Google Merchant Center accepts feeds this way, and so do most marketplaces and price comparison services.

An SFTP connection is a record of its own, shared by every feed that uploads to the same server; saving it connects it. The store owner makes it and points a feed at it in the admin, with a screenshot a step: the manual's SFTP connections and, for Google Merchant Center's server, The SFTP channel. This page has what the manual leaves to you: key authentication, why a save is refused, the host-key fingerprint, the upload and the transfer limits.

Arlanix_Sftp owns reusable connections and transfers, without a dependency on ProductFeed. Arlanix_ProductFeed owns the SFTP channel, its feed settings and validation, and the checks for feeds using a connection. Transfer failures become channel failures at the adapter boundary.

arlanix_product_feed.sftp_connection_id is a nullable foreign key to the selected connection. Several feeds may share a connection. The database prevents deleting a referenced connection, including through direct SQL. Deleting a feed leaves the connection intact; switching to another channel clears the reference during the save. UsageGuard provides the admin's message naming the feeds that use it.

Feed::getSftpConnectionId() reads the column with the feed row, without loading another section. The form saves the reference as a feed field; it has no copy in arlanix_product_feed_config.

The connection form

From a feed form whose channel is SFTP, + next to the connection picker opens the same form in a panel.

Field What to enter
Name Your own name for the connection: Warehouse SFTP, Google Merchant Center.
Host The server's host name or IP address, with no sftp:// in front.
Port 22 unless the server says otherwise. Google Merchant Center uses 19321.
Username The SFTP login.
Authentication Password or Private key.
SHA-256 host-key fingerprint The server's SSH host-key fingerprint; see Find the host-key fingerprint.
Password For password authentication. On a later edit, leaving it blank keeps the stored password, unless the host, port, username or fingerprint changed: the stored password is never sent to another server, so it is asked for again.
Private key, Private-key passphrase For key authentication: the private key and its passphrase, if it has one. Choose a key file reads the key from its file in the browser; the form then names the file and the kind of key (OpenSSH, PEM or PuTTY), never the key itself. A public key (.pub) or a file that is no key is refused on the spot. Paste the key instead opens a box for a key that is not in a file. On a later edit, leaving them empty keeps the stored ones, unless the host, port, username or fingerprint changed: then whatever was not entered again is dropped and asked for.

Saving connects the connection: the module reaches the server, compares its host key with the fingerprint and logs in. Saving a change to its host, port, username, authentication, fingerprint or any secret connects it again; renaming it does not.

Test Connection checks the saved connection. A failed test marks it Failed and blocks delivery until it connects again. A failed upload leaves the connection status unchanged.

When the save is refused

Check from the Magento host or container that runs cron:

  • DNS resolution and outbound access to the configured SFTP port;
  • the server's firewall or IP allow-list;
  • the host-key fingerprint, confirmed with the server owner;
  • the username and password, or the private key and its passphrase.

Inspect var/log/arlanix.log for the underlying SSH or network exception. Client-facing messages and actions are in SFTP connections.

The upload

Remote file name or path is a bare file name, google-shopping.xml, for the account's root directory, which is what Google Merchant Center expects; or an absolute path, /feeds/google-shopping.xml, for a server of your own. The directory must already exist.

Where the server can rename a file over another in one step, as OpenSSH servers do, the file is uploaded under a temporary name and renamed into place, so the server never sees a half-written feed. Each upload uses its own hidden sibling, .<name>.arlanix-sftp.<random>.tmp, so overlapping uploads cannot rename or remove each other's temporary file. Failed uploads attempt to remove their own temporary file. A process killed before cleanup can leave one behind; remove it on the SFTP server after confirming that its upload is no longer running. Google Merchant Center's server cannot rename atomically, so there the file is written under its own name, in a single upload.

Before publishing, the module compares the remote file size with the local file. A truncated upload fails; on an atomic server the previous published file stays in place.

After an upload, a failure to close the local temporary source is logged; it does not replace the upload result.

When the server is slow or down

A delivery waits on the server for a limited time, so one feed whose server stops answering cannot hold up the others in the same cron run. By default it allows 10 seconds to reach the server, agree the keys and log in, 30 seconds for any one answer after that, and an average upload speed of 50 KB a second, with at least a minute for any file.

A timeout while reading the server host key uses the same one-minute reconnect pause as a connection timeout.

For a server that is far away or a link that is slow, raise the limits under Stores → Configuration → Arlanix → Developer → SFTP delivery; the arlanix_sftp/transfer/* rows of Settings name them.

For transfer messages shown in the admin, see SFTP delivery errors.

Where the server renames atomically, a given-up upload leaves the published file as it was. Where it writes in place, as Google Merchant Center's does, the file may be left half-written until the next delivery replaces it. A failed feed is tried again later, each failure in a row waiting longer: see When a run fails.

Find the host-key fingerprint

Every SSH server identifies itself with a host key. Before logging in, the module computes the SHA-256 fingerprint of the key the server presents and compares it with the one stored on the connection. If they differ, nothing is sent. This is what stops a feed, and the password with it, from going to a server that only pretends to be yours.

The field takes the OpenSSH form of a SHA-256 fingerprint: SHA256: followed by 43 characters, for example:

SHA256:glAmvVKxBWXcUTPHGNA5+R0Oz/qOkA0MwZ1yJB8FeK4

Spaces around or inside the value, and a trailing =, are dropped when the connection is saved, and the 43 characters given alone get SHA256: in front of them. An MD5 fingerprint (85:19:8a:fb:…) is not accepted.

Google Merchant Center

Merchant Center shows its SFTP server, port, username and fingerprint when a data source is added with Add a file using SFTP or Google Cloud Storage: the manual's The SFTP channel shows each step. It prints the fingerprint as SHA256: +0f4…, with a space after the colon; it is taken as it is, or as the characters after SHA256: alone.

Any other server

Ask whoever runs the server for the SHA-256 fingerprint of its host key; a hosting provider or marketplace usually publishes it next to the SFTP credentials.

If you can reach the server from a computer with OpenSSH (any Mac or Linux machine, or Windows with OpenSSH installed), read the fingerprint yourself:

ssh-keyscan -p PORT HOST 2>/dev/null | ssh-keygen -lf -

Replace PORT with the server's SSH port, 22 unless the server says otherwise, and HOST with its host name.

It prints one line per key the server offers, for example:

256 SHA256:glAmvVKxBWXcUTPHGNA5+R0Oz/qOkA0MwZ1yJB8FeK4 sftp.example.com (ED25519)
4096 SHA256:2rK+thAm1pVGMIeacFuBB9ZP9xziD78DBgdz5q4Xmu0 sftp.example.com (RSA)

The module checks the key it negotiates with the server. When the server offers several, that is the first of these it supports: ED25519, then ECDSA, then RSA. In that example output, enter the ED25519 line.

On a server you administer, the same fingerprints come from the keys themselves:

ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub

Confirm a fingerprint read over the network with the server's owner, or with the value printed on the server, before saving it: a fingerprint accepted blindly protects nothing. When the server replaces its host key, verification fails until the field is updated.