node.js - 使用 node js 将文件上传到 ftp 服务器
问题描述
我正在尝试使用节点 js 将文件从本地机器上传到 ftp 服务器。以下是我尝试过的代码。我收到错误为“getaddrinfo ENOTFOUND https://owncloud.askgroup.co.in/remote.php/dav/files/jlotlikar/”。
class FTPClient {
constructor(host = 'localhost', port = 21, username = 'anonymous', password = 'guest', secure = false) {
this.client = new ftp.Client();
this.settings = {
host: host,
port: port,
user: username,
password: password,
secure: secure
};
}
upload(sourcePath, remotePath, permissions) {
let self = this;
(async () => {
try {
let access = await self.client.access(self.settings);
let upload = await self.client.upload(fs.createReadStream(sourcePath), remotePath);
let permissions = await self.changePermissions(permissions.toString(), remotePath);
} catch(err) {
console.log(err);
}
self.client.close();
})();
}
close() {
this.client.close();
}
changePermissions(perms, filepath) {
let cmd = 'SITE CHMOD ' + perms + ' ' + filepath;
return this.client.send(cmd, false);
}
}
const client = new FTPClient('https://owncloud.askgroup.co.in/remote.php/dav/files/jlotlikar/', 443, 'jlotlikar', 'June@2020', false);
client.upload('./cid.xml', 'HRMS_ExpenseReport/upload.xml', 443);
我无法连接到服务器。我是节点和 ftp 传输的新手。有人可以帮助我连接到 ftp 服务器并通过节点 js 上传文件吗?
解决方案
推荐阅读
- xml - 尝试通过 VBA 中的标记名称查询 XML 节点,可能是命名空间问题?
- django - 在 docker 中提供的 Django 静态文件使用 findstatic 但来自服务器的 404 找到
- python - 如何在 PyQt4 中访问 QGIS-2.14 的 QString
- java - 方法引用可以指向封闭类吗?
- maven - maven-enforcer-plugin 导致的依赖收敛错误
- sql - SQL - 如何查找两行之间缺少值的条目
- java - 编写一个正则表达式来确定匹配的数量并提取所需的字符串
- firebase - 基于文档ID数组从firebase批量读取 - Swift 4
- spring-boot - 会话管理不适用于 Spring Boot 和 Zuul 代理
- python - 我的函数如何将 csv 文件作为输入?