I have a SFTP server hosting some files. How to hit my SFTP server from Catalyst and upload the files to Catalyst filestore?
1. Create a catalyst project and initialize the project in your local machine. You can refer to the help documentation for the same
here.
2. Install Catalyst CLI in order to work with Catalyst in your local machine.
You can refer to the help documentation for the same here.2. Create an advancedIO function from the Catalyst CLI while initializing the project.
3. Navigate to your function directory(~/{project_name}/functions/{function_name}) in your terminal
4. Install the necessary npm packages that are used in the function by executing the commands below
- npm install ssh2-sftp-client
5. Paste the given code. Modify your hostname, port number, username and password. Navigate back to your project directory.
- "use strict";
- const Client = require('ssh2-sftp-client');
- module.exports = async(req, res) => {
- connectToSFTPServer();
- res.write("hit");
- res.end();
- };
- async function connectToSFTPServer() {
- const sftp = new Client();
- const remoteHost = ''; //replace your SFTP host
- const remotePort = ; //replace your port number (default is 22 for SFTP)
- const remoteUsername = ''; //replace your SFTP server username
- const remotePassword = ''; //replace your SFTP server password
-
- try {
- await sftp.connect({
- host: remoteHost,
- port: remotePort,
- username: remoteUsername,
- password: remotePassword
- });
- console.log('Connected to SFTP server');
- // Perform SFTP operations here
- const remoteFilePath = '{your_remote_path}';
- const files = await getFilesInDirectory(sftp, remoteFilePath);
- console.log('Files in the remote directory:');
- files.forEach((file) => {
- console.log(file);
- });
- // Disconnect from the SFTP server
- await sftp.end();
- console.log('Disconnected from SFTP server');
- } catch (err) {
- console.error('Error:', err.message);
- }}
- async function getFilesInDirectory(client, remotePath) {
- const entries = await client.list(remotePath);
- const files = [];
- for (const entry of entries) {
- if (entry.type === 'd') {
- // If the entry is a directory, recursively call the function
- const subdirectoryPath = `${remotePath}/${entry.name}`;
- const subdirectoryFiles = await getFilesInDirectory(client, subdirectoryPath);
- files.push(...subdirectoryFiles);
- } else if (entry.type === '-') {
- // If the entry is a regular file, add it to the files array
- files.push(entry.name);
- }}
- return files;
- }
6. Run catalyst serve in order to test your function in local debugging.
7. Run catalyst deploy in order to deploy your function to the development environment. You can hit your function by using the URL generated while deploying the function. You can refer the help documentation for the same here.
Announcements
[Webinar] Catalyst Cloud Browser in Action: PDF & Web Rendering Solutions for Regulated Industries
Hi everyone, Have you ever struggled with rigid PDF tools or clunky rendering logic in BFSI or healthcare apps? Do your clients struggle to deliver compliant, dynamic, and automated documents — and most are still stuck with brittle, server-heavy PDF generation?
Announcing Catalyst Developer Bootcamps in India - Zoho Community
Hey everyone! We're excited to announce a set of developer bootcamps dedicated to Catalyst! These bootcamps are aimed to empower developers to build, scale, and deploy applications with speed and precision, using Catalyst. Whether you're a newcomer or
[Webinar] Upgrade Retail Experiences with Serverless & AI
Ever wondered if you could build lightning-fast, intelligent retail solutions and experiences without touching infrastructure? Join our upcoming live session to explore how you can combine the agility of serverless with the power of large language models
[Webinar] Powering Industry Innovation: Building Unified Solutions with Catalyst
Struggling with fragmented apps or patchwork workflows across teams? Join us for a practical session on how developers are building unified, scalable industry solutions using Catalyst by Zoho—without wrangling with infrastructure. In this live session,
[Webinar] Bridging the Gap: Middleware for Cloud & On-Prem Integration with Catalyst by Zoho
Integrating cloud and on-prem systems can be complex - but it doesn’t have to be. Join us for a live webinar where we break down how middleware simplifies integrations, enhances scalability, and ensures secure data exchange. 🔹 Learn from Experts – Chris