节点-FTP-获取并重新启动
我创建了一个效果很好的FTP应用程序。 我可以上传和下载。我显示进度。 我可以恢复上传,但是... 我有一个恢复下载的问题。
我使用此代码重新启动下载。
// When Connection Ready
clientFtp.on('ready', function(){
// Source and Destination determination
var serverFile = "example_file_on_server.zip";
var localFile = "example_file_on_client.zip";
// List Remote File
clientFtp.list(serverFile,function(erreurListage, serverElementList) {
// Get Total File Weight
serverFileSize = serverElementList[0].size;
// Get Local File Info
localFileInfo = fs.statSync(localFile);
let restartSize = localFileInfo.size;
// Forcing for Restart from...
clientFtp.restart(restartSize,function(erreurRedemarrage){
// Initialization
tailleDownload = restartSize;
// Get File
clientFtp.get(serverFile, function(erreurRecuperation, stream) {
stream.pipe(fs.createWriteStream(localFile, {flag:'r+',start: restartSize}));
stream.on('data',function(buffer){
tailleDownload = buffer.length+tailleDownload;
pourcentageDownload = (tailleDownload/serverFileSize*100).toFixed(0);
console.log(pourcentageDownload);
});
});
});
});
});
我必须指定用于读取下载流的代码在不重新启动的情况下效果很好。 但是,当我将其与RESTART一起使用时,我有一个尺寸良好但不可读取的文件(这是zip文件)。该文件似乎损坏了。
注意:我使用R+标志并重新启动,但我使用它们正确...?
I created an FTP application that works well.
I can upload and download. I display the progression.
I can resume a upload but...
I have an issue to resume a download.
I use this code to restart a download.
// When Connection Ready
clientFtp.on('ready', function(){
// Source and Destination determination
var serverFile = "example_file_on_server.zip";
var localFile = "example_file_on_client.zip";
// List Remote File
clientFtp.list(serverFile,function(erreurListage, serverElementList) {
// Get Total File Weight
serverFileSize = serverElementList[0].size;
// Get Local File Info
localFileInfo = fs.statSync(localFile);
let restartSize = localFileInfo.size;
// Forcing for Restart from...
clientFtp.restart(restartSize,function(erreurRedemarrage){
// Initialization
tailleDownload = restartSize;
// Get File
clientFtp.get(serverFile, function(erreurRecuperation, stream) {
stream.pipe(fs.createWriteStream(localFile, {flag:'r+',start: restartSize}));
stream.on('data',function(buffer){
tailleDownload = buffer.length+tailleDownload;
pourcentageDownload = (tailleDownload/serverFileSize*100).toFixed(0);
console.log(pourcentageDownload);
});
});
});
});
});
I must specify that the code used for reading the download stream works well without restarting.
But when I use it with restart, I have a file with a good size but not readable (it's a zip file). The file seems corrupted.
Note : I use r+ flag and restart but I use them correcty...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我回答我的问题,然后开始:rtfm !!!
为什么...?因为它是 flags ,而不是
我继续使用此信息。
不要在createWritestream中使用启动。
如果您在FTP连接上使用重新启动,则无需在CreateWritestream中放置启动选项。
此代码工作正常
stream.pipe(fs.CreateWriteStream(localfile,{flags:'a'}));
>I answer to my question and I begin with : RTFM !!!
Why...? Because it's flags for options and not flag
I continue with this information.
Don't use start in createWriteStream.
If you use restart on FTP connection, you don't need to put start option in createWriteStream.
This code works fine
stream.pipe(fs.createWriteStream(localFile,{flags: 'a'}));