Modules@robinpath/ftp
ftp

@robinpath/ftp

0.1.3Node.jsPublic

FTP and SFTP file transfer operations

FTP

FTP and SFTP file transfer: connect, upload, download, list, mkdir, rename, and delete

Package: @robinpath/ftp | Category: Web | Type: Utility

Authentication

any "server" {"protocol": "sftp", "host": "example.com", "user": "admin", "pass": "..."}

Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.

Use Cases

Use the ftp module when you need to:

  • Upload a local file to remote server -- Use ftp.upload to perform this operation
  • Download a remote file -- Use ftp.download to perform this operation
  • List files in a remote directory -- Use ftp.list to perform this operation
  • Create a remote directory -- Use ftp.mkdir to perform this operation
  • Delete a remote file -- Use ftp.remove to perform this operation

Quick Reference

FunctionDescriptionReturns
connectConnect to an FTP or SFTP server{name, protocol, connected}
uploadUpload a local file to remote server{uploaded}
downloadDownload a remote file{downloaded}
listList files in a remote directoryArray of file info
mkdirCreate a remote directoryTrue
removeDelete a remote fileTrue
renameRename/move a remote fileTrue
closeClose an FTP/SFTP connectionTrue

Functions

connect

Connect to an FTP or SFTP server

Module: ftp | Returns: object -- {name, protocol, connected}

any "server" {"protocol": "sftp", "host": "example.com", "user": "admin", "pass": "..."}
ParameterTypeRequiredDescription
namestringYesConnection name
optionsobjectYes{protocol, host, port, user, pass, secure, privateKey}

upload

Upload a local file to remote server

Module: ftp | Returns: object -- {uploaded}

any "server" "./file.txt" "/remote/file.txt"
ParameterTypeRequiredDescription
namestringYesConnection
localPathstringYesLocal file
remotePathstringYesRemote path

download

Download a remote file

Module: ftp | Returns: object -- {downloaded}

any "server" "/remote/file.txt" "./file.txt"
ParameterTypeRequiredDescription
namestringYesConnection
remotePathstringYesRemote path
localPathstringYesLocal path

list

List files in a remote directory

Module: ftp | Returns: array -- Array of file info

any "server" "/uploads"
ParameterTypeRequiredDescription
namestringYesConnection
pathstringNoRemote path (default /)

mkdir

Create a remote directory

Module: ftp | Returns: boolean -- True

any "server" "/uploads/new"
ParameterTypeRequiredDescription
namestringYesConnection
pathstringYesRemote path

remove

Delete a remote file

Module: ftp | Returns: boolean -- True

any "server" "/old/file.txt"
ParameterTypeRequiredDescription
namestringYesConnection
pathstringYesRemote path

rename

Rename/move a remote file

Module: ftp | Returns: boolean -- True

any "server" "/old.txt" "/new.txt"
ParameterTypeRequiredDescription
namestringYesConnection
fromstringYesCurrent path
tostringYesNew path

close

Close an FTP/SFTP connection

Module: ftp | Returns: boolean -- True

any "server"
ParameterTypeRequiredDescription
namestringYesConnection

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Connection "..." not foundCheck the error message for details
@desc "Validate result"
do
  set $result as any "server" "./file.txt" "/remote/file.txt"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate

Retrieve all items and loop through them.

@desc "Iterate results"
do
  set $result as any "server" "/uploads"
  each $item in $result
    print $item
  end
enddo

2. Multi-step FTP workflow

Chain multiple ftp operations together.

@desc "Execute operation"
do
  set $r_connect as any "server" {"protocol": "sftp", "host": "example.com", "user": "admin", "pass": "..."}
  set $r_upload as any "server" "./file.txt" "/remote/file.txt"
  set $r_download as any "server" "/remote/file.txt" "./file.txt"
  print "All operations complete"
enddo

3. Safe connect with validation

Check results before proceeding.

@desc "Validate result"
do
  set $result as any "server" {"protocol": "sftp", "host": "example.com", "user": "admin", "pass": "..."}
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (3)

VersionTagPublished
0.1.3latest21 days ago
0.1.221 days ago
0.1.11 months ago
Install
$ robinpath add @robinpath/ftp

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.3
LicenseMIT
Unpacked Size7.3 KB
Versions3
Weekly Downloads28
Total Downloads28
Stars0
Last Publish21 days ago
Created1 months ago

Keywords

Category

web