# SFTP Sales Channel

### 1. Overview

The SFTP (Secure File Transfer Protocol) channel lets you exchange data by dropping CSV files on a secure server. It’s ideal if you prefer file-based workflows instead of APIs.

---

### 2. Features

- **Four File Types**: Orders, Products, Inventory, Fulfilments
- **Automatic Processing**: Files are processed on a schedule
- **Secure Transfer**: All data moves over SFTP
- **Column Mapping**: You can map your own column names
- **File Tracking**: Processed files go into a `processed/` folder and get a timestamp suffix
- **Error Handling**: Errors are logged for you to review under channel transactions

---

### 3. Setup

#### 3.1 Basic Configuration

You will need to supply these details when you add the SFTP channel in your system settings:

- **Host** (e.g. `sftp.example.com`)
- **Port** (usually `22`)
- **Username**
- **Password**
- **Base path** (optional; defaults to `/`)

#### 3.2 Directory Structure

When you connect, the system creates these folders automatically under your base path:

```
/
├── orders/
│   └── processed/
├── products/
│   └── processed/
├── inventory/
└── fulfilments/


```

---

### 4. File Guidelines

- **Maximum lines**: 5,000 per file
- **Format**: CSV (headers in first row)
- **Filenames**: Any name is fine—just drop into the correct folder (orders, products, inventory, fulfilments)
- **Processing order**: Oldest modified file first

**Orders files with multiple items**

- Repeat all order-level columns on each row
- Fill in only the `item_`prefixed columns with that item’s data
- Example: a 2-item order becomes 2 rows identical except for `item_` columns
- **Import grouping**: The system will automatically group rows by `order_id`.

**Fulfilments files with multiple items**

- Repeat all non-`item_` columns on each row
- Use the `item_`prefixed columns for each fulfilled item’s data
- Example: a 2-item shipment becomes 2 rows identical except for `item_` columns

---

### 5. File Format Requirements

#### 5.1 Orders

Required columns:

```
order_id
order_date
customer_name
customer_email
shipping_address_name
shipping_address_company_name
shipping_address_line_one
shipping_address_line_two
shipping_address_city
shipping_address_country_iso_code
shipping_address_zip
shipping_address_phone
billing_address_name
billing_address_company_name
billing_address_line_one
billing_address_line_two
billing_address_city
billing_address_country_iso_code
billing_address_zip
billing_address_phone
item_price_currency
item_discount_currency
item_discount_tax_currency


```

#### 5.2 Products

Required columns:

```
product_id
product_alt_id
sku


```

#### 5.3 Inventory

Required columns:

```

product_id
product_alt_id
sku
quantity


```

#### 5.4 Fulfilments

Required columns:

```
order_id
tracking_number
courier
item_id
item_product_sku
item_quantity


```

---

### 6. Sync Intervals

By default, the system checks for new files at these intervals. You can change them per channel if you need to.

<table id="bkmrk-file-type-interval-o"><thead><tr><th>File Type</th><th>Interval</th></tr></thead><tbody><tr><td>Orders</td><td>180 seconds (3 min)</td></tr><tr><td>Products</td><td>43 200 seconds (12 h)</td></tr><tr><td>Inventory</td><td>300 seconds (5 min)</td></tr><tr><td>Fulfilments</td><td>300 seconds (5 min)</td></tr></tbody></table>

---

### 7. Best Practices

1. **File Naming**
    - Use clear names (e.g. `orders_20250508.csv`)
    - Include a timestamp
    - Avoid special characters
2. **Processing**
    - Wait until the file is fully uploaded
    - Check the `processed/` folder to confirm success
    - Review channel logs for any errors
3. **Security**
    - Use strong, unique passwords
    - Rotate credentials regularly
    - Restrict SFTP access to only the needed folders
4. **Performance**
    - Keep files under a few hundred megabytes each
    - Don’t drop dozens of files at once
    - Stick to the recommended sync intervals

---

### 8. Example File Structure

**Orders CSV**

```
order_id,order_date,customer_name,customer_email,shipping_address_name,shipping_address_company_name,shipping_address_line_one,shipping_address_line_two,shipping_address_city,shipping_address_country_iso_code,shipping_address_zip,shipping_address_phone,item_id,item_product_sku,item_quantity
ORD123,2024-03-20 10:00:00,John Doe,john@example.com,John Doe,ACME Inc,123 Main St,Apt 4B,New York,US,10001,+1234567890,ITEMA,SKU123,1
ORD123,2024-03-20 10:00:00,John Doe,john@example.com,John Doe,ACME Inc,123 Main St,Apt 4B,New York,US,10001,+1234567890,ITEMB,SKU456,2


```

**Fulfilments CSV**

```
order_id,tracking_number,courier,item_id,item_product_sku,item_quantity
ORD123,TRK123456,USPS,ITEMA,SKU123,1
ORD123,TRK123456,USPS,ITEMB,SKU456,2


```

---

### 9. Troubleshooting

- **Connection Errors**
    - Check host, port, username and password
    - Ensure the base path exists
- **File Processing Errors**
    - Verify CSV format, headers and max line count
    - Check file and folder permissions
    - Look in the channel logs for error messages
- **Sync Problems**
    - Confirm the channel is set to “active”
    - Review any rate-limit messages in your logs

---

### 10. Support

If you still have questions or run into issues:

1. Review the channel logs in your dashboard.
2. Double-check your CSV headers, folder layout, and line count.
3. Contact our support team with the exact error message and a screenshot of your folder structure.