Making FTP requests

Since v1.277.0 GoErp supports FTP requests in dynamics. This feature allows to upload or download files to/from servers through FTP protocol as well as a couple of additional actions like moving files, getting directory list, etc.

Warning

Since v1.301.3 FTPGet and FTPPut are deprecated and will be removed in future versions. Instead, use FTP as a method while initializing the request and pass action name in cmd through PostParam.

Input parameters

Initialization of the request is made through FTP method type. Like so: <input type="hidden" name="CustomApi.Api.FTP.file" value="localhost:2121">. Value in this case contains the FTP server host with port. Port is mandatory parameter. If provider not specified the port, then the default ports for ftp 21,2121, and for ftps 990.

Actions request and response parameters

All requests expecting credentials and cmd to be passed through PostParam type:

  • cmd - FTP command (or action). All available commands are listed below.
  • schema - ftp or ftps. If not set, then GoErp will try to get it from the link and if fails then uses ftp.
  • username - FTP server username.
  • password - FTP server password.

get

Input parameters:

  • cmd - get
  • path - Path to the file on the server. Example: /path/to/file.txt.

Response:

{
  "status": "success",
  "base64File": "base64 encoded file content"
}

Example

<form method="post">
  <input type="hidden" name="CustomApi.Api.FTP.r" value="localhost:2121">
  <input type="hidden" name="CustomApi.Api.PostParam.r.schema" value="ftp">
  <input type="hidden" name="CustomApi.Api.PostParam.r.username" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.password" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.cmd" value="get">
  <input type="text" name="CustomApi.Api.PostParam.r.path" value="/path/to/file.txt">
  <button type="submit">Go</button>
</form>

store

Input parameters:

  • cmd - store
  • path - Path to the file on the server. Example: /path/to/file.txt.
  • file - file to upload (must be part of the multipart/form-data form).

Response:

{
  "status": "success"
}

Example

<form method="post" enctype="multipart/form-data">
  <input type="hidden" name="CustomApi.Api.FTP.r" value="localhost:2121">
  <input type="hidden" name="CustomApi.Api.PostParam.r.schema" value="ftp">
  <input type="hidden" name="CustomApi.Api.PostParam.r.username" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.password" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.cmd" value="store">
  <input type="text" name="CustomApi.Api.PostParam.r.path" value="/path/to/file.txt">
  <input type="file" name="CustomApi.Api.PostParam.r.file" value="">
  <button type="submit">Go</button>
</form>

storeBody

Input parameters:

  • cmd - store
  • path - Path to the file on the server. Example: /path/to/file.txt.
  • body - content of the file to upload.
  • encoding - encoding of the file content if applied. Empty for no encoding. Supported values: base64.

Response:

{
  "status": "success"
}

Example

<form method="post">
  <input type="hidden" name="CustomApi.Api.FTP.r" value="localhost:2121">
  <input type="hidden" name="CustomApi.Api.PostParam.r.schema" value="ftp">
  <input type="hidden" name="CustomApi.Api.PostParam.r.username" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.password" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.cmd" value="storeBody">
  <input type="text" name="CustomApi.Api.PostParam.r.path" value="/path/to/file.txt">
  <input type="text" name="CustomApi.Api.PostParam.r.encoding" value="base64">
  <!-- "Hello GoErp!" encoded with base64 -->
  <input type="file" name="CustomApi.Api.PostParam.r.body" value="SGVsbG8gR29FcnAh">
  <button type="submit">Go</button>
</form>

rename or move

Input parameters:

  • cmd - rename
  • fromPath - Path to the file on the server to rename.
  • toPath - New path to the file on the server. Directory will be created if not exists.

Response:

{
  "status": "success"
}

Example

<form method="post">
  <input type="hidden" name="CustomApi.Api.FTP.r" value="localhost:2121">
  <input type="hidden" name="CustomApi.Api.PostParam.r.schema" value="ftp">
  <input type="hidden" name="CustomApi.Api.PostParam.r.username" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.password" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.cmd" value="rename">
  <input type="text" name="CustomApi.Api.PostParam.r.fromPath" value="/path/to/file.txt">
  <input type="text" name="CustomApi.Api.PostParam.r.toPath" value="/path/to/archive/file.txt">
  <button type="submit">Go</button>
</form>

remove

Removing root directory is not allowed.

Input parameters:

  • cmd - remove
  • path - Path to the file or folder on the server to remove.

Response:

{
  "status": "success"
}

Example

<form method="post">
  <input type="hidden" name="CustomApi.Api.FTP.r" value="localhost:2121">
  <input type="hidden" name="CustomApi.Api.PostParam.r.schema" value="ftp">
  <input type="hidden" name="CustomApi.Api.PostParam.r.username" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.password" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.cmd" value="remove">
  <input type="text" name="CustomApi.Api.PostParam.r.path" value="/path/to/file.txt">
  <button type="submit">Go</button>
</form>

nameList

Displaying the names of files and directories in the specified path (subdirectories not included). Every element in the list has detailed information about entry.

Input parameters:

  • cmd - nameList
  • path - Path to the directory.

Response:

{
  "status": "success",
  "data": [
    "testencoded.json",
    "old-archive",
    "testbody.json"
  ]
}

Example

<form method="post">
  <input type="hidden" name="CustomApi.Api.FTP.r" value="localhost:2121">
  <input type="hidden" name="CustomApi.Api.PostParam.r.schema" value="ftp">
  <input type="hidden" name="CustomApi.Api.PostParam.r.username" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.password" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.cmd" value="nameList">
  <input type="text" name="CustomApi.Api.PostParam.r.path" value="/path/to/dir">
  <button type="submit">Go</button>
</form>

list

Displaying detailed information of files and directories in the specified path (subdirectories not included).

Input parameters:

  • cmd - list
  • path - Path to the directory.

Response:

  • Type - 0 for file, 1 for directory.
{
  "status": "success",
  "data": [
    {
      "Name": "archive",
      "Size": 4096,
      "Mode": "drwxr-xr-x",
      "ModeBits": 2147484141,
      "ModTime": "2025-03-25T13:47:39+02:00",
      "Type": "dir"
    }
  ]
}

Example

<form method="post">
  <input type="hidden" name="CustomApi.Api.FTP.r" value="localhost:2121">
  <input type="hidden" name="CustomApi.Api.PostParam.r.schema" value="ftp">
  <input type="hidden" name="CustomApi.Api.PostParam.r.username" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.password" value="test">
  <input type="hidden" name="CustomApi.Api.PostParam.r.cmd" value="list">
  <input type="text" name="CustomApi.Api.PostParam.r.path" value="/path/to/dir">
  <button type="submit">Go</button>
</form>

Error response

Payload structure for all actions is the same:

{
  "error": "550 Could not access file: open /tmp/my-data: no such file or directory",
  "status": "error"
}