[英]Zip file unable to expand after being posted to S3 from SFTP server using node and AWS lambda
[英]Accessing and Copying Files from SFTP server using aws lambda nodejs
我正在嘗試使用 aws lambda 函數訪問 sftp 服務器,但它一直返回 null,我不知道為什么。 主機、用戶名和密碼是正確的,因為我使用 WinSCP 測試了連接。 我也嘗試連接到其他免費的 sftp 服務器,但響應一直返回 null。 我不確定我在腳本中做錯了什么。 我確實安裝了 npm 包,然后壓縮文件並將 zip 文件上傳到 aws lambda。
exports.handler = async (event) => {
let Client = require('ssh2-sftp-client');
let Path = '/path';
let sftp = new Client();
sftp.connect({
host: 'host',
port: 22,
username: 'username',
password: 'password'
}).then(() => {
return sftp.list(Path);
}).then(() => {
context.done();
}).catch((err) => {
console.log('Catch Error: ', err);
context.fail();
});
};
已經 9 個月了,所以我希望它得到解決,但如果其他人需要解決方案:
exports.handler = (event) => {
let Client = require('ssh2-sftp-client');
let Path = '/path';
let sftp = new Client();
return sftp.connect({
host: 'host',
port: 22,
username: 'username',
password: 'password'
}).then(() => {
return sftp.list(Path);
}).then((list) => {
// If you want to do something with the list, do it here
// else just return the list from the function above and remove this
return list;
}).catch((err) => {
console.log('Catch Error: ', err);
throw new Error(err);
});
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.