Skip to content

Commit cba6023

Browse files
authored
Merge pull request #23 from unverbraucht/ftp-set-timeout
Allow to set FTP timeout through options.
2 parents f79bd10 + fd2941e commit cba6023

File tree

6 files changed

+77
-5
lines changed

6 files changed

+77
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@samkirkland/ftp-deploy",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"private": false,
55
"description": "Deploy files to a ftp server",
66
"main": "dist/module.js",

src/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export async function deploy(args: IFtpDeployArgumentsWithDefaults, logger: ILog
125125

126126
createLocalState(localFiles, logger, args);
127127

128-
const client = new ftp.Client();
128+
const client = new ftp.Client(args.timeout);
129129

130130
global.reconnect = async function () {
131131
timings.start("connecting");

src/main.test.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HashDiff } from "./HashDiff";
2-
import { IFileList, currentSyncFileVersion, IFile } from "./types";
2+
import { IFileList, currentSyncFileVersion, IFile, IFtpDeployArgumentsWithDefaults } from "./types";
33
import { Record } from "./types";
44
import { applyExcludeFilter, getDefaultSettings, ILogger, Timings } from "./utilities";
55
import path from "path";
@@ -589,6 +589,7 @@ describe("getLocalFiles", () => {
589589
exclude: [],
590590
"log-level": "standard",
591591
security: "loose",
592+
timeout: 30000,
592593
});
593594

594595
const mainYamlDiff = localDirDiffs.data.find(diff => diff.name === "workflows/main.yml")! as IFile;
@@ -703,6 +704,69 @@ describe("getLocalFiles", () => {
703704
});
704705
});
705706

707+
708+
describe("getDefaultSettings", () => {
709+
test("path validation", async () => {
710+
expect(() => getDefaultSettings({
711+
server: "a",
712+
username: "b",
713+
password: "c",
714+
"local-dir": "noEndingSlash"
715+
})).toThrowError("local-dir should be a folder (must end with /)");
716+
717+
expect(() => getDefaultSettings({
718+
server: "a",
719+
username: "b",
720+
password: "c",
721+
"server-dir": "noEndingSlash"
722+
})).toThrowError("server-dir should be a folder (must end with /)");
723+
});
724+
725+
test("verify default settings", async () => {
726+
expect(getDefaultSettings({
727+
server: "a",
728+
username: "b",
729+
password: "c",
730+
})).toEqual({
731+
server: "a",
732+
username: "b",
733+
password: "c",
734+
port: 21,
735+
protocol: "ftp",
736+
"local-dir": "./",
737+
"server-dir": "./",
738+
"state-name": ".ftp-deploy-sync-state.json",
739+
"dry-run": false,
740+
"dangerous-clean-slate": false,
741+
exclude: excludeDefaults,
742+
"log-level": "standard",
743+
security: "loose",
744+
timeout: 30000
745+
});
746+
});
747+
748+
test("verify default settings override", async () => {
749+
const customSettings: IFtpDeployArgumentsWithDefaults = {
750+
server: "a",
751+
username: "b",
752+
password: "c",
753+
port: 54321,
754+
protocol: "ftps-legacy",
755+
"local-dir": "./client/",
756+
"server-dir": "./server/",
757+
"state-name": ".customState.json",
758+
"dry-run": true,
759+
"dangerous-clean-slate": true,
760+
exclude: [],
761+
"log-level": "verbose",
762+
security: "strict",
763+
timeout: 1234
764+
};
765+
766+
expect(getDefaultSettings(customSettings)).toEqual(customSettings);
767+
});
768+
});
769+
706770
describe("error handling", () => {
707771
test("throws on error", async () => {
708772
const mockedLogger = new MockedLogger();

src/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@ export interface IFtpDeployArguments {
5757
* When using protocol "ftps" or "ftps-legacy" should the cert name need to match exactly?
5858
* Set this to "strict" to ensure your data is being encrypted
5959
*
60-
* Defautls to loose because of the sheer volume of shared hosts that give ftp domains a cert without a matching common name
60+
* Defaults to loose because of the sheer volume of shared hosts that give ftp domains a cert without a matching common name
6161
* @default "loose"
6262
*/
6363
security?: "strict" | "loose";
64+
65+
/**
66+
* Timeout in milliseconds for FTP operations as handled by underlying basic-ftp connection library.
67+
* @default 30000 (30 seconds)
68+
*/
69+
timeout?: number;
6470
}
6571

6672
export interface IFtpDeployArgumentsWithDefaults {
@@ -77,6 +83,7 @@ export interface IFtpDeployArgumentsWithDefaults {
7783
exclude: string[];
7884
"log-level": "minimal" | "standard" | "verbose";
7985
security: "strict" | "loose";
86+
timeout: number;
8087
}
8188

8289
export interface IFile {

src/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export function getDefaultSettings(withoutDefaults: IFtpDeployArguments): IFtpDe
188188
"exclude": withoutDefaults.exclude ?? excludeDefaults,
189189
"log-level": withoutDefaults["log-level"] ?? "standard",
190190
"security": withoutDefaults.security ?? "loose",
191+
"timeout": withoutDefaults.timeout ?? 30000,
191192
};
192193
}
193194

0 commit comments

Comments
 (0)