SFTP error connection (econnreset)

Hi,

I’m building an automated test for my application but I have a problem with the SFTP Node, I have a Econnereset error on each of my test.

Error: end: read ECONNRESET at Client.fn (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected]/node_modules/ssh2-sftp-client/src/utils.js:69:22) at Client.emit (node:events:531:35) at Socket.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected]/node_modules/ssh2/lib/client.js:805:12) at Socket.emit (node:events:519:28) at emitErrorNT (node:internal/streams/destroy:170:8) at emitErrorCloseNT (node:internal/streams/destroy:129:3) at processTicksAndRejections (node:internal/process/task_queues:90:21)

An other problem, when I set up my SFTP credentials, the button test spins indefinitely.

I tested to connect with the sftp client in CLI it works.

Thank you for your help.

Hey @michael78fr hope all is good. Welcome to the community.

If you are using Windows SSH Server to connect over SFTP, see if this topic answers your question:

Hi @jabbson,

Thank you, It’s the same problem, my SFTP server runs on Windows.

It’s a n8n self hosted, how can I change the sftp client package ?

Or maybe, do you know what is the last version of the docker version that it works ?

Hey @michael78fr, good question!

If you run self-hosted n8n, you could try to downgrade the version by replacing the package, it would look something like:

docker exec -it --user root n8n /bin/sh

mkdir -p /tmp/pin && cd /tmp/pin
npm init -y >/dev/null 2>&1
npm i [email protected] [email protected] --no-audit --no-fund

N8N_DIR=/usr/local/lib/node_modules/n8n

rm -rf "$N8N_DIR/node_modules/ssh2-sftp-client" \
       "$N8N_DIR/node_modules/ssh2"

cp -r node_modules/ssh2-sftp-client "$N8N_DIR/node_modules/"
cp -r node_modules/ssh2 "$N8N_DIR/node_modules/"

chown -R node:node "$N8N_DIR/node_modules/ssh2-sftp-client" \
                    "$N8N_DIR/node_modules/ssh2"

node -p "require('$N8N_DIR/node_modules/ssh2-sftp-client/package.json').version"
node -p "require('$N8N_DIR/node_modules/ssh2/package.json').version"

rm -rf /tmp/pin
exit

but this will be changing things in the ephemeral container.

If above works, you will need to re-build the docker image with new package.

thank you, I try this.

I tried to mount older image, but it failed because the db schema change in 1.109

It’s done but the SFTP node is always running the 12.0.1 version.

How to restart n8n without restart the docker ?

docker restart n8n is how you would restart a container without re-creating it.

I restarted the docker, but I don’t understand why my ftp client is always the same.

I checked the ssh2-sftp-client (10.0.3) and ssh (1.15.0)

Error: end: read ECONNRESET at Client.fn (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected]/node_modules/ssh2-sftp-client/src/utils.js:69:22) at Client.emit (node:events:531:35) at Socket.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected]/node_modules/ssh2/lib/client.js:805:12) at Socket.emit (node:events:519:28) at emitErrorNT (node:internal/streams/destroy:170:8) at emitErrorCloseNT (node:internal/streams/destroy:129:3) at processTicksAndRejections (node:internal/process/task_queues:90:21)

If you can create and share (through DM) credentials for this server, I could test, otherwise, I unfortunately have no windows machines to test this.

Thank you for providing the credentials to your sftp server for tests. You are right, the previous approach wasn’t a success, because of some module locations. Here is what worked for me:

Shell into n8n container:

# Root shell
docker exec -u root -it n8n bash

Do some magic:

# 1) Build the pinned packages in isolation
rm -rf /tmp/pin && mkdir -p /tmp/pin && cd /tmp/pin
npm init -y >/dev/null 2>&1
npm i [email protected] [email protected] --no-audit --no-fund

# 2) Find the active pnpm node_modules directories used by n8n
PNPM_DIR=/usr/local/lib/node_modules/n8n/node_modules/.pnpm
SFTP_NODEMODS="$(ls -d $PNPM_DIR/ssh2-sftp-client@*/node_modules | head -n1)"
SSH2_NODEMODS="$(ls -d $PNPM_DIR/ssh2@*/node_modules | head -n1)"

# Safety check
test -d "$SFTP_NODEMODS" && test -d "$SSH2_NODEMODS" || { echo "pnpm paths not found"; exit 1; }

# 3) Replace the package folders
rm -rf "$SFTP_NODEMODS/ssh2-sftp-client" "$SSH2_NODEMODS/ssh2"
cp -r node_modules/ssh2-sftp-client "$SFTP_NODEMODS/"
cp -r node_modules/ssh2 "$SSH2_NODEMODS/"

# 4) Copy direct deps of ssh2-sftp-client AND of promise-retry (the one complaining about err-code)
copy_dep () {
  local dep="$1"
  if [ -d "node_modules/$dep" ]; then
    rm -rf "$SFTP_NODEMODS/$dep"
    cp -r "node_modules/$dep" "$SFTP_NODEMODS/"
  fi
}

# Direct deps of [email protected]
for d in $(node -p "Object.keys(require('./node_modules/ssh2-sftp-client/package.json').dependencies||{}).join(' ')"); do
  copy_dep "$d"
done

# Direct deps of promise-retry (pulls in err-code, retry, etc.)
for d in $(node -p "Object.keys(require('./node_modules/promise-retry/package.json').dependencies||{}).join(' ')"); do
  copy_dep "$d"
done

# 5) Fix ownership
chown -R node:node "$SFTP_NODEMODS/ssh2-sftp-client" "$SSH2_NODEMODS/ssh2" "$SFTP_NODEMODS"/*

# 6) Verify (should print 10.0.3 and 1.15.0)
node -p "require('$SFTP_NODEMODS/ssh2-sftp-client/package.json').version"
node -p "require('$SSH2_NODEMODS/ssh2/package.json').version"

exit

then restart the container:

docker restart n8n

Opened a bug for this:

This Dockerfile is worked for me

FROM n8nio/n8n:1.114.0
USER root
RUN cd /usr/local/lib/node_modules/n8n && \
    rm -rf /tmp/pin && mkdir -p /tmp/pin && cd /tmp/pin && npm init -y >/dev/null 2>&1 && npm i [email protected] [email protected] --no-audit --no-fund && \
    PNPM_DIR=/usr/local/lib/node_modules/n8n/node_modules/.pnpm && \
    SFTP_NODEMODS="$(ls -d $PNPM_DIR/ssh2-sftp-client@*/node_modules | head -n1)" && \
    SSH2_NODEMODS="$(ls -d $PNPM_DIR/ssh2@*/node_modules | head -n1)" && \
    (test -d "$SFTP_NODEMODS" && test -d "$SSH2_NODEMODS") || { echo "pnpm paths not found, skipping SFTP fix"; exit 0; } && \
    rm -rf "$SFTP_NODEMODS/ssh2-sftp-client" "$SSH2_NODEMODS/ssh2" && \
    cp -r node_modules/ssh2-sftp-client "$SFTP_NODEMODS/" && \
    cp -r node_modules/ssh2 "$SSH2_NODEMODS/" && \
    copy_dep () { \
        local dep="$1"; \
        if [ -d "node_modules/$dep" ]; then \
            rm -rf "$SFTP_NODEMODS/$dep" && \
            cp -r "node_modules/$dep" "$SFTP_NODEMODS/"; \
        fi; \
    } && \
    for d in $(node -p "Object.keys(require('./node_modules/ssh2-sftp-client/package.json').dependencies||{}).join(' ')"); do \
        copy_dep "$d"; \
    done && \
    if [ -d "node_modules/promise-retry" ]; then \
        for d in $(node -p "Object.keys(require('./node_modules/promise-retry/package.json').dependencies||{}).join(' ')"); do \
            copy_dep "$d"; \
        done; \
    fi && \
    chown -R node:node "$SFTP_NODEMODS/ssh2-sftp-client" "$SSH2_NODEMODS/ssh2" "$SFTP_NODEMODS"/* && \
    node -p "require('$SFTP_NODEMODS/ssh2-sftp-client/package.json').version" && \
    node -p "require('$SSH2_NODEMODS/ssh2/package.json').version" && \
    rm -rf /tmp/pin
USER node

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