Skip to content

TcpConnect (TCP connectivity check)

ts
function TcpConnect(
  host:      string,  // required
  port:      number,  // required
  timeoutMs?: number   // optional, default 5000
): boolean;

NOTE

This function is available as of Syncplify Server! v7.1.1. If you are running an older version, upgrade to v7.1.1 or later to use it.

Attempts to open a TCP connection to host:port. Returns true if the connection is established, false if it cannot be established within timeoutMs milliseconds. The connection is closed immediately after the test; no data is exchanged.

This is useful for verifying that a remote server is reachable before attempting a file transfer or API call.

ParameterTypeRequirementExplanation
hoststringrequiredHostname or IP address to connect to. IPv6 addresses are supported (e.g. ::1).
portnumberrequiredTCP port number to connect to
timeoutMsnumberoptionalConnection timeout in milliseconds. Default: 5000
Return valueExplanation
trueThe connection was established successfully
falseThe connection failed or the timeout expired

Examples

Basic connectivity check

ts
if (!TcpConnect('sftp.partner.com', 22)) {
  Log('SFTP server is unreachable. Aborting transfer.');
} else {
  // proceed with the transfer
}

Shorter timeout for fast internal networks

ts
var ok = TcpConnect('10.0.1.50', 443, 1000);
if (ok) {
  Log('Internal API is up.');
}

Retry pattern

ts
var retries = 5;
var up = false;
for (var i = 0; i < retries; i++) {
  if (TcpConnect('db.internal', 5432, 2000)) {
    up = true;
    break;
  }
  Log('Attempt ' + (i + 1) + ' failed, retrying...');
  Sleep(3000);
}
if (!up) {
  Log('Database unreachable after ' + retries + ' attempts.');
}