basic-ftp | FTP client for Node.js , supports FTPS | HTTP library
kandi X-RAY | basic-ftp Summary
kandi X-RAY | basic-ftp Summary
The first example will connect to an FTP server using TLS, get a directory listing, upload a file and download it as a copy. Note that the FTP protocol doesn't allow multiple requests running in parallel. The next example deals with directories and their content. First, we make sure a remote path exists, creating all directories as necessary. Then, we make sure it's empty and upload the contents of a local directory. If you encounter a problem, it may help to log out all communication with the FTP server.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of basic-ftp
basic-ftp Key Features
basic-ftp Examples and Code Snippets
Community Discussions
Trending Discussions on basic-ftp
QUESTION
ftp sends data in a writable stream and azure stageblock method accepts data in readable stream and when i am trying to save data i am getting error. Error: body must be a string, Blob, ArrayBuffer, ArrayBufferView, or a function returning NodeJS.ReadableStream.
...ANSWER
Answered 2020-Jun-25 at 06:50According to my test, we can use the following code to download files from FTP server then upload file to Azure blob
QUESTION
I'm currently working on a backup script with NodeJS. The script downloads a directory and its files und subdirectories recursively using FTP/FTPS. I'm using the basic-ftp package to do the FTP calls.
When I try to download a big directory with a lot of subdirectories, I get the Maximum call stack size exceeded
error, but I don't find why and where it happens. I don't see any infinity loop or any missing return calls. After hours of debugging, I have no more ideas.
I don't use the downloadDirTo
method from basic-ftp, because I don't want to stop downloading after a error happend. When an error occures it should keep going and it should add the error to the log file.
The repository is here: https://github.com/julianpoemp/webspace-backup.
As soon as the FTPManager is ready, I call the doBackup method (see method in BackupManager). This method calls the downloadFolder method defined in FTPManager.
...ANSWER
Answered 2019-Nov-06 at 00:53Inside the FtpManager.downloadFolder
function, I see recursive calls to the same downloadFolder
method with an await
. Your Maximum call stack exceeded
error could come from there, since your initial call will need to keep everything in memory while traversing all subdirectories.
Instead of await
ing everything recursively, you could setup a queue system, with an algorithm like this:
- Add the current folder to a queue
- While that queue is not empty:
- Get the first folder in the queue (and remove it from it)
- List all entries in it
- Download all files
- Add all subfolders to the queue
This allows you to download a lot of folders in a loop, instead of using recursion. Each loop iteration will run independently, meaning that the result of the root directory download won't depend on the deeeeeep file tree inside it.
Using a queue managerThere are plenty of queue manager modules for NodeJS, which allow you to have concurrency, timeouts, etc. One I've used in the past is simply named queue. It has a lot of useful features, but will require a little more work to implement in your project. Hence, for this answer, I used no external queue module, so that you can see the logic behind it. Feel free to search for queue
, job
, concurrency
...
I wanted to implement that logic directly into your own code, but I don't use Typescript, so I thought I'd make a simple folder copy function, which uses the same logic.
Note: For simplicity, I've not added any error handling, this is just a proof of concept! You can find a demo project which uses this here on my Github.
Here is how I've done it:
QUESTION
I have been struggling with various FTP Node modules to try and get anything working in AWS Lambda. The best and most popular seems to be "Basic-FTP" that also supports async/await. But I just cannot get it to download files when any code is added beneath the FTP function.
I don't want to add the fs functions within the FTP async function as I need to solve what is causing the break when any code below is added and I also have other bits of code to add and work with the downloaded file and it's content later:
FTP SUCCESS - When the async function is used only with no fs code beneath it
FTP FAILURE - Adding the fs readdir/readFile functions or any other code below
ERROR Error: ENOENT: no such file or directory, open '/tmp/document.txt'
ANSWER
Answered 2019-Mar-02 at 19:14The problem is that you are getting lost when creating an async function inside your handler. Since example()
is async, it returns a Promise. But you don't await
on it, so the way it has been coded, it's kind of a fire and forget thing. Also, your Lambda is being terminated before your callbacks are triggered, so even if it got to download you would not be able to see it.
I suggest you wrap your callbacks in Promises so you can easily await
on them from your handler function.
I have managed to make it work: I have used https://dlptest.com/ftp-test/
for testing, so change it accordingly. Furthermore, see that I have uploaded the file myself. So if you want to replicate this example, just create a readme.txt on the root of your project and upload it. If you already have this readme.txt file on your FTP server, just delete the line where it uploads the file.
Here's a working example:
QUESTION
I am using a single Node module basic-ftp
to download a txt file in AWS Lambda and place it in the /tmp/ directory within the Lambda function.
I then want to work with the txt file and its contents outside of the FTP function.
I am using Async and Promises and have got a bit lost with the code. The current error returned in AWS Lambda is
...ANSWER
Answered 2019-Feb-18 at 21:11finalData is only defined within example which returns it, but you're not assigning this to anything. Combined with Luca Kiebel's comment, try adding
const finalData = await example();
then log that out.
Because finalData is defined within the function example, it is only available within that function and any function defined within that function.
You Don't Know JS explains this better than I can
QUESTION
I am using just a single Node package, basic-ftp
to try and download a TXT file and write the contents to the console. Further down the line I will be editing the text so will need to use fs
. Just struggling to work with the output from createWriteStream
from within the FTP program.
Can anyone help me write a TXT file to the /tmp/ file within AWS Lambda and then the correct syntax to open and edit the file after createWriteStream
has been used?
ANSWER
Answered 2019-Feb-15 at 23:42Pretty sure your fs.createWriteStream()
has to use an absolute path to /tmp
in Lambdas. Your actual working directory is var/task
not /
.
Also, if you're using fs.createWriteStream() you'll need to wait for the finish
event before reading from the file. Somethign like this...
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install basic-ftp
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page