我正在尝试从sftp服务器读取文件并将该文件流式传输到s3存储桶中。我无法将文件流式传输到s3存储桶中。是的,文件路径完全正确。我不确定自己在做什么错。当我运行代码时,它甚至不会尝试将流上传到存储桶中,因为我没有任何上传控制台日志。
const aws = require('aws-sdk');
const s3 = new aws.S3();
const Client = require('ssh2').Client;
const conn = new Client();
const connSettings = {
host: event.serverHost,
port: event.port,
username: event.username,
password: event.password
};
exports.handler = function(event) {
conn.on('ready', function() {
conn.sftp(function(err, sftp) {
if (err) {
console.log("Errror in connection", err);
conn.end()
} else {
console.log("Connection established");
let readStream = sftp.createReadStream(remoteFilePath);
console.log(`Read Stream ${readStream}`)
// readStream outputs [object Object] to the console
const uploadParams = {
Bucket: s3Bucket,
Key: 'fileName',
Body: readStream
}
s3.upload (uploadParams, function (err, data) {
if (err) {
console.log("Error", err);
} if (data) {
console.log("Upload Success", data.Location);
}
});
conn.end()
}
});
}).connect(connSettings);
}
我希望能够将readStream从sftp服务器流式传输到s3存储桶。
答案 0 :(得分:2)
conn.end()
立即终止连接。将其移至s3.upload()
回调的 inside 中,以便在关闭连接之前实际传输数据。
答案 1 :(得分:1)
这是Node 12的一个有效示例,我相信您正在尝试实现以下目标:
select st.ID, st.start_date,
case when st.start_date is null then 'No' else 'Yes' end as Success,
case when st.start_date is null then 'Yes' else 'No' end as Fail
from Start st
left join Success sc o sc.ID = st.ID