mscdex / node-ftp

An FTP client module for node.js
MIT License
1.13k stars 244 forks source link

Binary Image Gets Corrupted When PUT Over FTP #253

Open agilliam-cmg opened 5 years ago

agilliam-cmg commented 5 years ago

Every image I PUT() to a server using FTP client gets corrupted. I've tested with jpeg and png, all are damaged during transfer. Some characters are missing and some are displaced:

async sendImage(image) { try { const credentials = await getFtpCredentials(this.platform); console.log('Sending files via FTP client'); return new Promise((resolve, reject) => { let ftpClient = new ftp(); ftpClient.on('ready', () => { console.log(Putting ${image.path} onto server); // Set transfer type to binary ftpClient.binary(err => { if(err) reject(err); else // image.content is binary string data ftpClient.put(image.content, image.path, (err) => { if (err) { reject(err); } console.log('Closing FTP connection'); ftpClient.end(); resolve(FTP PUT for ${image.path} successful!`); });

                });
            });
            console.log('Connecting to FTP server');
            ftpClient.connect(credentials);
        });

` Here's a copy of the image before sending over FTP and here's a corrupted copy after. Please compare the two using a binary editor or regular notepad. I hope this issue can be resolved as I like this library!

Thanks!

besserwisser commented 5 years ago

Have you found a workaround?

agilliam-cmg commented 5 years ago

@besserwisser No, I'm using the basic-ftp library instead.