Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
theophilusx committed Aug 5, 2024
1 parent ca11895 commit 50fa471
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 88 deletions.
9 changes: 4 additions & 5 deletions examples/downloadDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
// Example of using the downloadDir() method to download a directory
// from a remote SFTP server to a local directory

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import SftpClient from '../src/index.js';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const SftpClient = require('../src/index.js');

const config = {
host: process.env.SFTP_SERVER,
Expand Down
9 changes: 4 additions & 5 deletions examples/exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

// sample use of exists() to test for remote dir/file existance

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import Client from '../src/index.js';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const Client = require('../src/index.js');

const config = {
host: process.env.SFTP_SERVER,
Expand Down
11 changes: 4 additions & 7 deletions examples/fastget.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use strict';

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import SftpClient from '../src/index.js';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const SftpClient = require('../src/index.js');

const config = {
host: process.env.SFTP_SERVER,
Expand Down
12 changes: 4 additions & 8 deletions examples/fastput.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict';

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import { join } from 'node:path';
import SftpClient from '../src/index.js';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const SftpClient = require('../src/index.js');

const config = {
host: process.env.SFTP_SERVER,
Expand Down
11 changes: 5 additions & 6 deletions examples/get-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
// to retrieve the file and then uses a pass through stream to pipe
// the contents to standard out.

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import Client from '../src/index.js';
import { PassThrough } from 'node:stream';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const Client = require('../src/index.js');
const { PassThrough } = require('node:stream');

const config = {
host: process.env.SFTP_SERVER,
Expand Down
11 changes: 6 additions & 5 deletions examples/get-writeable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
// Example of using a writeable with get to retrieve a file.
// This code will read the remote file, convert all characters to upper case
// and then save it to a local file

import Client from '../src/index.js';
import { join } from 'node:path';
import { createWriteStream } from 'node:fs';
import through from 'through2';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const Client = require('../src/index.js');
const { createWriteStream } = require('node:fs');
const through = require('through2');

const config = {
host: 'arch-vbox',
Expand Down
11 changes: 5 additions & 6 deletions examples/large-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
// Note that in most cases you are far better off using a stream rather than
// a buffer.

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import { readFileSync } from 'node:fs';
import Client from '../src/index.js';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const { readFileSync } = require('node:fs');
const Client = require('../src/index.js');

const config = {
host: process.env.SFTP_SERVER,
Expand Down
7 changes: 3 additions & 4 deletions examples/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
// Simple script which just display a directory listing for a
// remote sftp directory specified on the command line

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const Client = require('../src/index.js');

const config = {
Expand Down
11 changes: 5 additions & 6 deletions examples/listing-with-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
// Simple script to produce a directory listing of a remote sftp directory
// with error checking and using a key and passphrase to control access.

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import { readFileSync } from 'fs';
import Client from '../src/index.js';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const { readFileSync } = require('node:fs');
const Client = require('../src/index.js');

const config = {
host: process.env.SFTP_SERVER,
Expand Down
9 changes: 4 additions & 5 deletions examples/mkdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
// sample mkdir use
// Usage: node ./mkdir.js <remote dir path> [debug]

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import Client from '../src/index.js';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const Client = require('../src/index.js');

const config = {
host: process.env.SFTP_SERVER,
Expand Down
10 changes: 4 additions & 6 deletions examples/multiple-get.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import { join } from 'path';
import Client from '../src/index.js';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const Client = require('../src/index.js');

const config = {
host: process.env.SFTP_SERVER,
Expand Down
10 changes: 4 additions & 6 deletions examples/multiple-get2.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import { join } from 'path';
import Client from '../src/index.js';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const Client = require('../src/index.js');

const config = {
host: process.env.SFTP_SERVER,
Expand Down
9 changes: 4 additions & 5 deletions examples/realpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
// The 'realpath' functionality varies across sftp servers,
// especdially with respect to handling '.' and '..'

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import Client from '../src/index.js';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const Client = require('../src/index.js');

const client = new Client();
const targetPath = process.argv[2];
Expand Down
4 changes: 2 additions & 2 deletions examples/sftp-config-example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync } from 'node:fs';
import Client from '../src/index.js';
const { readFileSync } = requ8ire('node:fs');
const Client = require('../src/index.js');

const keyFile = `${process.env.HOMfe}/.ssh/id_ed25519.pub`;

Expand Down
11 changes: 5 additions & 6 deletions examples/stream-put.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
* passing the readStream to put(). You could just pass the buffer directly.
* We are using the ReadStream just for demonstration purposes
*/
const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import { Readable } from 'node:stream';
import Client from '../src/index';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const { Readable } = require('node:stream');
const Client = require('../src/index');

const config = {
host: process.env.SFTP_SERVER,
Expand Down
10 changes: 4 additions & 6 deletions examples/uploadDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
// Example of using the uploadDir() method to upload a directory
// to a remote SFTP server

const dotenvPath = new URL('../.env', import.meta.url);
import dotenv from 'dotenv';
dotenv.config({ path: dotenvPath });

import { join } from 'path';
import SftpClient from '../src/index.js';
const { join } = require('node:path');
const dotenvPath = join(__dirname, '..', '.env');
require('dotenv').config({ path: dotenvPath });
const SftpClient = require('../src/index.js');

const config = {
host: process.env.SFTP_SERVER,
Expand Down

0 comments on commit 50fa471

Please sign in to comment.