使用节点js将文件上传到ftp服务器

时间:2020-07-20 12:27:31

标签: node.js ftp ftp-client

我正在尝试使用节点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上传文件。

0 个答案:

没有答案