1

i m trying to download 4 GB file from SFTP using node js using ssh2-sftp-client module. My main problem is around 40%(not to be exact sometimes 45 also) of file get downloaded after than downloading stops neither an error occurs not any progress is shown in the download.

i have tried on different system using different internet and facing same issue. Kindly help i m badly struck on this issue.

let Client = require('ssh2-sftp-client');
let sftp = new Client();
function DownloadFromSFTP(){
sftp.connect({
host: '127.0.0.1',
port: '8080',
username: 'username',
password: '******'
}).then(() => {
return sftp.list('/');
}).then((data) => {
if(data.length>0){
var remotepath='/'+data.name;
var localpath=="/path/to/local/folder"+data.name;
sftp.fastGet(remotePath, localPath, {
concurrency:640,
Chunksize:32768},function(err){
if(err) throw err
console.log("downloaded successfully")
});
}
}).catch((err) => {
console.log(err, 'catch error');
});
}

if file is not downloaded fully then it should show error or if it is disconnected from sftp how to check is ftp connected or not

bab951
  • 41
  • 12
  • That may or may not be an sftp problem. It could be a local file system problem ... It could be a remote server issue.... does it work with 2gb files? – Ahmed Masud Jun 19 '19 at 17:34
  • when i download the same file from the sftp using filezilla it downloaded smoothly. problem only occur when i try to download using the code. if i try to download small file it works very well – bab951 Jun 19 '19 at 17:36

1 Answers1

1

i was able to solve the issue . The main issues which was occurring is that SFTP stops responding and my networks goes to 0 following is the updated code

    let Client = require('ssh2-sftp-client');
    let sftp = new Client();
    function DownloadFromSFTP(){
    sftp.connect({
    host: '127.0.0.1',
    port: '8080',
    username: 'username',
    password: '******',
keepaliveInterval :2000,
keepaliveCountMax :20
    }).then(() => {
    return sftp.list('/');
    }).then((data) => {
    if(data.length>0){
    var remotepath='/'+data.name;
    var localpath=="/path/to/local/folder"+data.name;
    sftp.fastGet(remotePath, localPath, {
    concurrency:640,
    Chunksize:32768},function(err){
    if(err) throw err
    console.log("downloaded successfully")
    });
    }
    }).catch((err) => {
    console.log(err, 'catch error');
    });
    }

adding

 keepaliveInterval :2000,
    keepaliveCountMax :20

to my code did the trick for me

bab951
  • 41
  • 12