Download file from ftp using angular 5+? - node.js

I'm trying to use the npm library called ftp-client (https://www.npmjs.com/package/ftp-client) to download a simple image from my ftp server in my Angular 5 application. I copy-pasted the example but it does not seem to be working, I see this error in the console:
The code is:
var ftpClient = require('../../../../../node_modules/ftp-client'),
config = {
host: 'ftp://myhost.com',
port: 21,
user: 'admin',
password: 'admin'
},
options = {
logging: 'basic'
},
client = new ftpClient(config, options);
client.connect(function (){
client.download('/images/no-img.jpg', 'test/', {
overwrite: 'all'
}, function (result) {
console.log(result);
});
});
Just in case, ng -v output is:
Angular CLI: 1.7.4
Node: 8.11.1
OS: win32 x64
Angular: 5.2.11
What do you think it can be?
Thanks!!

I think the problem is with typescript notation
you should use :
import * as ftpClient from 'ftp-client';
instead of :
var ftpClient = require('../../../../../node_modules/ftp-client'),

Related

Deno keeps giving me the same type of error on different modules

I am trying to connect with the Jira REST api using Deno. My Library of choice is Jira.js. I've used both installing the node_modules locally and referencing the modules through the library link. To no avail, deno gives me the same type of error.
This is my code.
//import { Version2Client } from "./node_modules/jira.js/src/index.ts";
import * as jira from "https://deno.land/x/jira#v2.10.4/src/index.ts";
const client = new Version2Client({
host: 'https://FFFFFF.atlassian.net',
authentication: {
basic: {
email: 'FFFFFFF#gmail.com',
apiToken: 'FFFFFFFF',
},
},
});
async function main() {
const projects = await client.projects.getAllProjects();
console.log(projects);
}
main();
jira.js does not support Deno directly. But you can run it with NPM compatibility mode, for that, you'll need to replace your import to use npm: specifier: npm:jira.js
import { Version2Client } from 'npm:jira.js';
const client = new Version2Client({
host: 'https://FFFFFF.atlassian.net',
authentication: {
basic: {
email: 'FFFFFFF#gmail.com',
apiToken: 'FFFFFFFF',
},
},
});
// ...

how to execute remote operation to windows machine via nodejs

I finally joined the community
So for my first question in this community:
Generally I want to execute some remote operations to a remote windows machine in node.js (of course I have permissions, credential and so on to the remote machine).
Specifically, right now I'm trying to retrieve list of services from windows machine.
I've tried using the wmi-client package in order to do so:
const WmiClient = require('wmi-client');
var wmi = new WmiClient({
username: '*****', //credentials - username
password: '*****', //credentials - password
host: '*********', // remote windows machine
});
wmi.query(`Select * from Win32_Service`, function (err, result) {
console.log(result);
});
but I keep receiving error: Exit code: 44125. Invalid Global Switch.
I'll mention that using wmi in powershell make no issues for me.
but when I trying to use the same technology in nodejs its failed.
what am I doing wrong? Any other suggestions?
just to mention, when I need to retrieve same info from linux machine I easiliy do it using 'simple-ssh' package, without any issues:
const SSH = require('simple-ssh');
var ssh = new SSH({
host: '*******', // remote linux machine
user: '*******', // credentials - username
pass: '*******' // credentials - password
});
ssh.exec(`systemctl list-units --full -all`, {
out: function(stdout) {
// stdout as expected
}
}).start()});
but things getting complicated when trying to do the same for windows remote machine.
any ideas?
Thank you very much!
seems like the following is working for me:
var exec = require('node-ssh-exec');
var config = {
host: '*******',
username: '***',
password: '***'
},
command = 'sc query';
exec(config, command, function (error, response) {
if (error) {
throw error;
}
the response is as expected, but for some reason the error associated with it is not empty:
{
errno: -4077,
code: "ECONNRESET",
syscall: "read",
level: "connection-socket",
}

Upload file on the FTP server via node js

I tried simple file upload on the FTP path via node js. For that I have installed ftp-client module.
index.js
const ftpClient = require("ftp-client");
// FTP Configuration
const config = {
host: '',
port: 22,
user: '',
password: ''
};
const options = {
logging: 'basic'
};
client = new ftpClient(config, options);
client.connect(function (result) {
client.upload(['./upload/test.txt'], '/opt/test_api', {
baseDir: 'ogrds',
overwrite: 'older'
}, function (result) {
console.log(result);
})
}
);
When tried to execute by node index.js command, this is neither giving any results nor moved the file to the FTP server.

Sails.js - Ignored attempt to bind route (/) to unknown controller :: home

I'm using Ubuntu 14.04 LTS and I'm trying to install this application that makes use of sails.js
When I try to run it with the command sails lift I get this error
error: Ignored attempt to bind route (/) to unknown controller :: home.
This is my local.js file:
module.exports = {
port: process.env.PORT || 1337,
environment: process.env.NODE_ENV || 'development',
hookTimeout: 50000,
connections: {
'default': 'postgresql',
pgigg: {
adapter: 'sails-postgresql',
host: 'localhost',
port: 5432,
user: 'xtenspg',
password: 'xtenspg',
database: 'xtensdb',
pool: true,
ssl: false,
schema: true
},
},
fileSystemConnections: {
default: 'irodsRest',
irodsRest: {
type: 'irods-rest',
restURL: {
hostname: 'localhost',
port: 8080,
path: '/irods-rest/rest'
},
irodsHome: '/tempZone/home/rods',
repoCollection: 'xtens-repo',
landingCollection: 'landing',
username: 'rods',
password: 'rods'
}
},
defaultOperators: [{
firstName: 'default administrator',
lastName: 'sysadmin',
birthDate: '1970-01-01',
sex: 'N.A.',
email: 'blabla#gmail.com',
login: 'admin',
password: 'admin1982'
}
]
};
I have already installed Node.js and PostgreSQL 9.4. This is my configuration:
$ node -v
v5.0.0
$ sails -v
0.12.3
$ bower -v
1.7.9
$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
Can anyone help me?
Also make sure your file name is ended with controller.
For example
ProductSellerController not only
ProductSeller
I have experienced a similar situation, it occurred when the route was specified in the config/routes.js. But the controller or the method in the controller was not loaded or is missing. Otherwise if your routes for / is
'/': {
view: 'homepage'
}
that is the default one. Check if homepage.ejs file is exist in views folder.
bhapri is correct.
Have a look at xtens-app config/routes.js, where we find this:
'GET /': {controller: 'home'},
Yet there is no HomeController.js in api/controllers/
Simply comment or remove that line.
check the directory of controller and focus over lower and uper case of spell.

res.render doesn't render correctly after 1023 characters

I have a parent Express app, and a Ghost app as a child app, using Ghost as an npm module here.
I routed Ghost to be rendered at http://localhost:9000/blog. All the configuration works fine (Ghost will throw an error if the basic configuration isn't being provided correctly).
Here is my Ghost startup code
ghost({
config: path.join(__dirname, '/config/ghost.config.js')
}).then(function (ghostServer) {
app.use(ghostServer.config.paths.subdir, ghostServer.rootApp);
ghostServer.start(app);
});
here is my Ghost config
// # Ghost Configuration
// Setup your Ghost install for various [environments](http://support.ghost.org/config/#about-environments).
// Ghost runs in `development` mode by default. Full documentation can be found at http://support.ghost.org/config/
var path = require('path'),
config;
config = {
// ### Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
url: 'http://my-ghost-blog.com',
mail: {},
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
},
server: {
host: '127.0.0.1',
port: '2368'
}
},
// ### Development **(default)**
development: {
// The url to use when providing links to the site, E.g. in RSS and email.
// Change this to your Ghost blog's published URL.
url: 'http://localhost:9000/blog/',
// Example mail config
// Visit http://support.ghost.org/mail for instructions
// ```
// mail: {
// transport: 'SMTP',
// options: {
// service: 'Mailgun',
// auth: {
// user: '', // mailgun username
// pass: '' // mailgun password
// }
// }
// },
// ```
// #### Database
// Ghost supports sqlite3 (default), MySQL & PostgreSQL
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '../blog/data/ghost-dev.db')
},
debug: false
},
// #### Server
// Can be host & port (default), or socket
server: {
// Host to be passed to node's `net.Server#listen()`
host: '127.0.0.1',
// Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
port: '9000'
},
// #### Paths
// Specify where your content directory lives
paths: {
contentPath: path.join(__dirname, '../blog/')
}
},
// **Developers only need to edit below here**
// ### Testing
// Used when developing Ghost to run tests and check the health of Ghost
// Uses a different port number
testing: {
url: 'http://127.0.0.1:2369',
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost-test.db')
}
},
server: {
host: '127.0.0.1',
port: '2369'
},
logging: false
},
// ### Testing MySQL
// Used by Travis - Automated testing run through GitHub
'testing-mysql': {
url: 'http://127.0.0.1:2369',
database: {
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'root',
password : '',
database : 'ghost_testing',
charset : 'utf8'
}
},
server: {
host: '127.0.0.1',
port: '2369'
},
logging: false
},
// ### Testing pg
// Used by Travis - Automated testing run through GitHub
'testing-pg': {
url: 'http://127.0.0.1:2369',
database: {
client: 'pg',
connection: {
host : '127.0.0.1',
user : 'postgres',
password : '',
database : 'ghost_testing',
charset : 'utf8'
}
},
server: {
host: '127.0.0.1',
port: '2369'
},
logging: false
}
};
module.exports = config;
So basically, when I go to http://localhost:9000/blog, it isn't being rendered at all. Nothing. I was using Chrome and also testing it using Safari. Also tested those two without JavaScript turned on.
And then I try to do curl http://localhost:9000/blog, and try using a requester app (like Postman) and they returned the correct html string. I also tried to do a curl using the user agent as Chrome and as Safari, it also returns the correct html.
I traced down to ghost node_modules, and the renderer is in ghost > core > server > controllers > frontend > index.js in this line res.render(view, result)
I changed the res.render to be like this
res.render(view, result, function(err, string) {
console.log("ERR", err);
console.log("String", string);
res.send(string);
})
and there is no error, it logs the current string, but it doesn't render anything on the browser.
I tried curl, postman, works, but browser doesn't work.
then I tried to send a hello world string, it works, the browser rendered it.
Then I add the string length one by one, and it turns out, any str.length < 1023 will be able to be rendered by the browser, but once it get past that, it doesn't.
And I tried in my parent Express app, it is able to send string which length is more than 1023, and if I use the ghost module as a standalone, it also able to send string more than 1023.
So something must have happened between those two, but I don't know how to debug this.
Please help

Resources