Node.js 连接到 ftp 并下载文件
Node.js connect to ftp and download files
你好,我下载了这个 npm 模块来连接到我的 ftp: node-ftps
连接class
var FTPS = require('ftps');
var ftps = new FTPS({
host: 'myhost',
username: 'user',
password: 'mypw',
protocol: 'ftp'
});
ftps.exec(function (err, res) {
console.log();
});
如何检查连接是否成功以及如何从我的路径中获取所有文件!
尝试添加文件但出现错误我什至不知道我是否已连接
我建议你试试 node-ftp
,它也支持 ftps
,尽管 node-ftps
做同样的工作,但缺乏好的文档和示例。
在这里结帐,
https://github.com/mscdex/node-ftp
要设置连接并访问它的功能,您需要做的就是下载一个名为 ftp-client
的节点包装器,它是专门为 node-ftp
模块开发的。
您可以通过发出以下命令来安装此包装器,
npm install ftp-client
要初始化它,请使用以下命令,
var ftpClient = require('ftp-client'),
client = new ftpClient(config, options);
您可以在此处找到完整的示例代码,它将引导您了解我们如何连接到服务器,并同时上传 test
目录中的所有文件,仅覆盖服务器上找到的旧文件,并从 /public_html/test directory
.
下载文件
https://github.com/noodny/node-ftp-client#examples
希望对您有所帮助!
我最近尝试 node-ftp
并发现它在连接到一些较新的服务器时出现问题。特别是我无法连接到服务器版本 SSH-2.0-1.82_sshlib Globalscape
ssh2-sftp-client
对我有用。在连接选项中传递一个 debug:yourDebugFunction
参数以获得良好的调试输出。
https://www.npmjs.com/package/ssh2-sftp-client
let sftp = new Client();
sftp.connect({
host: '127.0.0.1',
port: '8080',
username: 'username',
password: '******'
}).then(() => {
return sftp.list('/pathname');
}).then(data => {
console.log(data, 'the data info');
}).catch(err => {
console.log(err, 'catch error');
});```
你好,我下载了这个 npm 模块来连接到我的 ftp: node-ftps
连接class
var FTPS = require('ftps');
var ftps = new FTPS({
host: 'myhost',
username: 'user',
password: 'mypw',
protocol: 'ftp'
});
ftps.exec(function (err, res) {
console.log();
});
如何检查连接是否成功以及如何从我的路径中获取所有文件!
尝试添加文件但出现错误我什至不知道我是否已连接
我建议你试试 node-ftp
,它也支持 ftps
,尽管 node-ftps
做同样的工作,但缺乏好的文档和示例。
在这里结帐,
https://github.com/mscdex/node-ftp
要设置连接并访问它的功能,您需要做的就是下载一个名为 ftp-client
的节点包装器,它是专门为 node-ftp
模块开发的。
您可以通过发出以下命令来安装此包装器,
npm install ftp-client
要初始化它,请使用以下命令,
var ftpClient = require('ftp-client'),
client = new ftpClient(config, options);
您可以在此处找到完整的示例代码,它将引导您了解我们如何连接到服务器,并同时上传 test
目录中的所有文件,仅覆盖服务器上找到的旧文件,并从 /public_html/test directory
.
https://github.com/noodny/node-ftp-client#examples
希望对您有所帮助!
我最近尝试 node-ftp
并发现它在连接到一些较新的服务器时出现问题。特别是我无法连接到服务器版本 SSH-2.0-1.82_sshlib Globalscape
ssh2-sftp-client
对我有用。在连接选项中传递一个 debug:yourDebugFunction
参数以获得良好的调试输出。
https://www.npmjs.com/package/ssh2-sftp-client
let sftp = new Client();
sftp.connect({
host: '127.0.0.1',
port: '8080',
username: 'username',
password: '******'
}).then(() => {
return sftp.list('/pathname');
}).then(data => {
console.log(data, 'the data info');
}).catch(err => {
console.log(err, 'catch error');
});```