Readable stream uploads but does not resolve
See original GitHub issueDescribe the bug
I am trying to upload a string of text. I have converted it into a readable stream, and am able to upload it to an FTP server, but the connection hangs, and the function does not resolve.
Possibly a duplicate of #8, but solution in thread wasn’t helpful – where would I push(null)
to the readableStream
?
Example code
import ftp from 'basic-ftp';
import path from 'path';
import {Readable} from 'stream';
async createFile(filepath, content) {
const {host, user, password} = this.options;
const client = new ftp.Client();
client.ftp.verbose = true;
try {
const dirname = path.dirname(filepath);
const basename = path.basename(filepath);
const readableStream = Readable.from(content, {
encoding: 'utf-8'
});
await client.access({host, user, password, secure: true});
await client.ensureDir(dirname);
await client.uploadFrom(readableStream, basename);
} catch (error) {
throw new Error(error.message);
}
client.close();
}
Console output
Connected to ##.##.###.#:21 (No encryption)
< 220 (vsFTPd 3.0.3)
> AUTH TLS
< 234 Proceed with negotiation.
Control socket is using: TLSv1.3
Login security: TLSv1.3
> USER ###
< 331 Please specify the password.
> PASS ###
< 230 Login successful.
> TYPE I
< 200 Switching to Binary mode.
> STRU F
< 200 Structure set to F.
> OPTS UTF8 ON
< 200 Always in UTF8 mode.
> OPTS MLST type;size;modify;unique;unix.mode;unix.owner;unix.group;unix.ownername;unix.groupname;
< 501 Option not understood.
> PBSZ 0
< 200 PBSZ set to 0.
> PROT P
< 200 PROT now Private.
> MKD www
< 550 Create directory operation failed.
> CWD www
< 250 Directory successfully changed.
> MKD test
< 550 Create directory operation failed.
> CWD test
< 250 Directory successfully changed.
> MKD _notes
< 257 "/home/username/www/test/_notes" created
> CWD _notes
< 250 Directory successfully changed.
Trying to find optimal transfer strategy...
> EPSV
< 229 Entering Extended Passive Mode (|||38221|)
Optimal transfer strategy found.
> STOR 2020-12-24-jeukk.md
< 150 Ok to send data.
Uploading to ##.##.###.#:38221 (TLSv1.3)
The connection then times out.
Which version of Node.js are you using?
Node v14.15.0
Additional context
Am I right in assuming the connection doesn’t close because basic-ftp
doesn’t know when the stream has ended/closed?
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
The upload file process not working with readable streams (I ...
I am uploading a file using fetch streams, but I need can calculate the upload progress. On the server I receive an corrupt...
Read more >Node.js & request module : Start upload from a readable stream
The code below waits until the user has finished his upload before starting the second upload (Though I'm not 100% sure about that)...
Read more >ReadableStream - Web APIs - MDN Web Docs
Chrome Edge
ReadableStream Full support. Chrome43. Toggle history Full support. Edge14...
ReadableStream() constructor Full support. Chrome43. Toggle history Full support. Edge79...
cancel Full support. Chrome43. Toggle...
Read more >Streams Standard
Readable streams are designed to wrap both types of sources behind a single, unified interface. For web developer–created streams, the ...
Read more >Stream | Node.js v19.3.0 Documentation
Data is buffered in Readable streams when the implementation calls stream.push(chunk) . If the consumer of the Stream does not call stream.read() ,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@alexandr2134 Huh, weird. I thought I did try copying and pasting your code, but couldn’t get it to work. But trying again today, and it’s now working beautifully! Thanks for your help 👍
did you try this code ?
this exact code works fine for me. Can you try to simply copy/paste it (without modifying it) and check? Replace your lines 42-44 with this.