Skip to content Skip to sidebar Skip to footer

Using Jsftp To Upload Files Results In Files Of Zero Size On Server

I'm trying to put files on my server with jsftp. Everytime I run my code I do get a file written to the server but it has 0 bytes. I'm certain that the user: host: etc are correct.

Solution 1:

I think I needed to read the file first. Here's what worked.

varJSFtp = require("jsftp");    
 var fs = require("fs");
 varFtp = newJSFtp({ 
     host: localStorage.host,
     port: Number(localStorage.port),
     user: localStorage.user,
     pass: localStorage.ftpPass
 });
 var local = filePath;
 var remote = localStorage.ftpPath + logName;
 fs.readFile(local, function(err, buffer) {
     if(err) {
         console.error(err);
         callback(err);
     }
     else {
         Ftp.put(buffer, remote, function(err) {
             if (err) {
                 console.error(err);
                 callback(err);
             }
             else {
                 alert(file + " - uploaded successfuly");
                 callback();
             }
         });
     }
 });

Solution 2:

I have the same question.(using jsftp to upload files results in files of zero size on vsftpd server)

make sure use console.error to print the error.

Ftp.put(buffer, remote, function(err) {
         if (err) {
             console.error(err);
             callback(err);
         }
         else {
             alert(file + " - uploaded successfuly");
             callback();
         }
     });

the error like that

{ [Error: connect ETIMEDOUT **192.168.0.4:64953**]code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  address: '192.168.0.4',
  port: 64953 }

because of my vsftpd using the PASV model,so when it return the port .jsftp modified the ip .I resolve this problem : modify jsftp.js (jsftp/lib/jsftp.js)

var fixhost;

varFtp = module.exports = function(cfg) {
    ...
    this.useList = cfg.useList || false;
    fixhost=this.host;//add
}

 Ftp.prototype.getPasvSocket = function(callback) {
    ...
    options.host=fixhost;//addvar socket = self._pasvSocket = Net.createConnection(options);
}

Post a Comment for "Using Jsftp To Upload Files Results In Files Of Zero Size On Server"