> For the complete documentation index, see [llms.txt](https://docs.editran.onesait.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.editran.onesait.com/documentacion-editran/connect-3.2-en/api/ejemplos/01_upload-send.md).

# 01 - script example - upload-send

This script is presented as a practical example to illustrate the possible use of the Editran APIs, showing how to integrate them into automated processes using PowerShell. Its purpose is to serve as a reference for developers and administrators who want to implement similar solutions in their environments.

The script is available at:

{% file src="/files/55f33c32bfcb1d98ac010dee5d9839f72754b3e6" %}

The upload-send.ps1 script has been designed to simplify and automate the process of uploading and sending files to communication channels within environments that require efficient and secure data management. This document describes how the script works, its parameters, the execution flow, and practical examples to make it easier to use both in interactive scenarios and in automated processes.

The tool is aimed at Windows and cross-platform environments, ensuring compatibility with PowerShell 5.x and PowerShell 7+, while avoiding specific dependencies that limit its portability. Thanks to its modular structure, the script allows credentials to be validated, directories to be updated, and channel sending to be executed in a controlled way, displaying clear progress and error messages.

The script **`upload-send.ps1`** automates the process of **uploading a file to a channel** for sending or bidirectional, and performing **the channel send**.

It consists of four main phases:

1. **Credential validation** Validation of the specified username and password.
2. **Directory retrieval** Obtains the directories of the indicated channel.
3. **Directory update** Updates the directories of the indicated channel with the path of the specified file.
4. **Channel sending**\
   Performs sending of the specified channel.

***

## Parameters

| Name          | Required | Description                                                                                 |
| ------------- | -------- | ------------------------------------------------------------------------------------------- |
| `server`      | Yes      | Server (http\:// or https\:// optional, https is used by default).                          |
| `user`        | Yes      | User identification (email address or account name).                                        |
| `password`    | Yes      | Password associated with the user. It can be passed as an argument or requested at runtime. |
| `channelCode` | Yes      | Channel code in format `local-remote-application`.                                          |
| `path`        | Yes      | Full path of the file to upload.                                                            |

***

## Script flow

1. Requests or receives the parameters.
2. Performs user validation.
3. If validation is correct, updates the channel directories with the file path.
4. If there are no errors, performs the channel sending.
5. Displays progress and error messages on the console.

If an error occurs in any of the functions, execution stops and a descriptive message is shown.

***

## Compatibility

* **PowerShell 5.x (classic Windows)**
* **PowerShell 7+ (Core / cross-platform)**

The script avoids using PS7-specific features to maintain compatibility with both environments.

***

## Usage examples

### 1. Run to display help

```powershell
PS> powershell -ExecutionPolicy Bypass -File ".\upload-send.ps1" -help
```

Expected output:

```txt
Syntax:
    upload-send [-options]
           (to upload a file to a specific channel and perform the send)
   or  upload-send -help | -h
           (to display this help)

where the options include:
    -servidor <host[:port]>
           Server (http:// or https:// optional, https is used by default)
    -usuario <user>
           User identification (email)
    -password <password>
           User password
    -codigoCanal <local-remote-application>
           Channel code in local-remote-application format
    -rutaFichero <path>
           Full path of the file to upload and send
    -help | -h
           Displays this help
```

### 2. Direct execution with parameters

```powershell
PS> powershell -ExecutionPolicy Bypass -File ".\upload-send.ps1"
    -servidor "MyServer"
    -usuario "user@company.com"
    -password "MySecurePassword"
    -codigoCanal "local-remote-app"
    -ruta "C:\temp\file.xml"
```

### 3. Run while requesting parameters interactively

```powershell
PS> powershell -ExecutionPolicy Bypass -File ".\upload-send.ps1"
```

```txt
Server: MyServer
User identification (email): user@company.com
User password: MySecurePassword
Channel code (format: local-remote-application): local-remote-app
Full path of the file to upload and send: C:\temp\file.xml
```

### 4. Alternative execution: initializing parameters in the file

Instead of passing all parameters on the command line, it is possible to define them by initializing them in the script. This can be useful for recurring or automated runs.

1. Edit the script.
2. Modify the following block to initialize the values of the parameters you want.

   ```powershell
   # --------------------------------------------------------------------
   #  Parameter initialization
   #  To assign a default value to a parameter, 
   #  remove the comment character '#' from the corresponding parameter
   # --------------------------------------------------------------------
   # $server = ''
   # $user = ''
   # $password = ''
   # $channelCode = ''
   # $filePath = ''
   ```
3. Save the script.
4. Run the script: interactively requesting the parameters that have not been initialized (point 3), or providing the parameters that have not been initialized (point 2).

***

### Example parameter file (`config.txt`)

```powershell
# Configuration parameters for upload-send
server=https://my-server.com:8443
user=user@example.com
password=MySecretPassword
channelCode=local-remote-application
filePath=C:\path\to\file.txt
```

## Expected output

```txt
===============================================
      FILE UPLOAD AND SEND SCRIPT
===============================================
This script allows you to upload a file to a channel
and execute the corresponding send in Connect.


===============================================
                VALIDATED DATA
===============================================
Server: MyServer
User: user@company.com
Password: ********
Channel code: local-remote-app
File path: C:\temp\file.xml
===============================================

Validating credentials...
[OK] Access authorized

Retrieving channel directories...
[OK] The directories of the channel local-remote-app were retrieved successfully

Updating channel directories...
[OK] The directories of the channel local-remote-app were updated successfully

Performing channel sending...
[OK] The channel local-remote-app was sent successfully
```

## Output with errors

If an error occurs, a red message with details will be shown, and the process will not continue.

Example:

```txt
===============================================
      FILE UPLOAD AND SEND SCRIPT
===============================================
This script allows you to upload a file to a channel
and execute the corresponding send in Connect.


===============================================
                VALIDATED DATA
===============================================
Server: MyServer
User: user@company.com
Password: ********
Channel code: local-remote-app
File path: C:\temp\file.xml
===============================================

Validating credentials...
[OK] Access authorized

Retrieving channel directories...
[OK] The directories of the channel local-remote-app were retrieved successfully

Updating channel directories...
[OK] The directories of the channel local-remote-app were updated successfully

Performing channel sending...
[ERROR] Trying to add a send directory to a reception channel (400)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.editran.onesait.com/documentacion-editran/connect-3.2-en/api/ejemplos/01_upload-send.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
