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.

Input parameters

Initialization of the request is made through FTPGet, FTPPut types. Like so: <input type="hidden" name="CustomApi.Api.FTPPut.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.

All request parameters should be provided through PostParam type. The following parameters are available:

  • file - content of the file to upload.
  • username - FTP server username.
  • password - FTP server password.
  • path - Path to the file on the server. Example: /path/to/file.txt.

Response body

In case of FTPGet requests, the response body will contain the file content.

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

In case of FTPPut requests, just a status message will be returned.

{
  "status": "success"
}

Both methods have the same error response structure.

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

Example

<h2>Upload file</h2>
<form method="post" enctype="multipart/form-data">
    <input type="hidden" name="CustomApi.Api.FTPPut.file" value="localhost:2121">
    <input type="hidden" name="CustomApi.Api.PostParam.file.username" value="test">
    <input type="hidden" name="CustomApi.Api.PostParam.file.password" value="test">
    <br>Path: <input type="text" name="CustomApi.Api.PostParam.file.path" value="">
    <br>File: <input type="file" name="CustomApi.Api.PostParam.file.file" value="">
    <button type="submit">Go</button>
</form>

<h2>Download file</h2>
<form method="post">
    <input type="hidden" name="CustomApi.Api.FTPGet.gFile" value="localhost:2121">
    <input type="hidden" name="CustomApi.Api.PostParam.gFile.username" value="test">
    <input type="hidden" name="CustomApi.Api.PostParam.gFile.password" value="test">
    <br>Path: <input type="text" name="CustomApi.Api.PostParam.gFile.path" value="">
    <button type="submit">Go</button>
</form>

<br>Response:<pre>{{ .Data.CustomApi.Api.Requests.gFile.Response.Raw | jsonPretty }}</pre>