1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2025-11-29 22:27:42 +02:00
Files
OpenIntegrations/docs/en/md/SFTP/File-management/Save-file.mdx
Vitaly the Alpaca (bot) 1120c732f0 Main build (Jenkins)
2025-10-20 19:41:52 +03:00

124 lines
3.9 KiB
Plaintext
Vendored

---
sidebar_position: 3
description: Save file and other functions to work with SFTP in the Open Integration Package, a free open-source integration library for 1C:Enterprise 8, OneScript and CLI
keywords: [1C, 1С, 1С:Enterprise, 1С:Enterprise 8.3, API, Integration, Services, Exchange, OneScript, CLI, SFTP]
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
# Save file
Saves the file from the server to the specified path
`Function SaveFile(Val Connection, Val Path, Val FileName) Export`
| Parameter | CLI option | Type | Required | Description |
|-|-|-|-|-|
| Connection | --conn | Arbitrary | ✔ | Existing connection or connection configuration |
| Path | --path | String | ✔ | Path to file on server |
| FileName | --file | String | ✔ | Path to save file on disk |
Returns: Map Of KeyAndValue - Processing result
<br/>
```bsl title="1C:Enterprise/OneScript code example"
Host = FunctionParameters["SSH_Host"];
Port = FunctionParameters["SSH_Port"];
UseProxy = True;
ProxySettings = Undefined;
AuthorizationType = "By login and password";
If AuthorizationType = "By login and password" Then
Login = FunctionParameters["SSH_User"];
Password = FunctionParameters["SSH_Password"];
SFTPSettings = OPI_SFTP.GetSettingsLoginPassword(Host, Port, Login, Password);
ElsIf AuthorizationType = "By key" Then
Login = FunctionParameters["SSH_User"];
PrivateKey = "./ssh_key";
PublicKey = "./ssh_key.pub";
SFTPSettings = OPI_SFTP.GetSettingsPrivateKey(Host, Port, Login, PrivateKey, PublicKey);
Else
Login = FunctionParameters["SSH_User"];
SFTPSettings = OPI_SFTP.GetSettingsViaAgent(Host, Port, Login);
EndIf;
If UseProxy Then
ProxyType = FunctionParameters["Proxy_Type"]; // http, socks5, socks4
ProxyAddress = FunctionParameters["Proxy_IP"];
ProxyPort = FunctionParameters["Proxy_Port"];
ProxyLogin = FunctionParameters["Proxy_User"];
ProxyPassword = FunctionParameters["Proxy_Password"];
ProxySettings = OPI_SFTP.GetProxySettings(ProxyAddress, ProxyPort, ProxyType, ProxyLogin, ProxyPassword);
EndIf;
Connection = OPI_SFTP.CreateConnection(SFTPSettings, ProxySettings);
If OPI_SFTP.IsConnector(Connection) Then
Path = "pic_from_disk.png";
FileName = GetTempFileName("bin");
Result = OPI_SFTP.SaveFile(Connection, Path, FileName);
Else
Result = Connection; // Error of connection
EndIf;
```
<Tabs>
<TabItem value="bash" label="Bash" default>
```bash
# JSON data can also be passed as a path to a .json file
oint sftp SaveFile \
--conn "{'proxy':{'login':'proxyuser','password':'***','port':'8071','proxy_type':'http','server':'127.0.0.1'},'set':{'auth_type':'private_key','host':'172.33.0.13','key_path':'***','passphrase':null,'password':null,'port':'2222','pub_path':'/tmp/0ryurmds.fdc.tmp','username':'bayselonarrend'}}" \
--path "pic_from_disk.png" \
--file "/tmp/mtyqchvr.xgl.bin"
```
</TabItem>
<TabItem value="bat" label="CMD/Bat" default>
```batch
:: JSON data can also be passed as a path to a .json file
oint sftp SaveFile ^
--conn "{'proxy':{'login':'proxyuser','password':'***','port':'8071','proxy_type':'http','server':'127.0.0.1'},'set':{'auth_type':'private_key','host':'172.33.0.13','key_path':'***','passphrase':null,'password':null,'port':'2222','pub_path':'/tmp/0ryurmds.fdc.tmp','username':'bayselonarrend'}}" ^
--path "pic_from_disk.png" ^
--file "/tmp/mtyqchvr.xgl.bin"
```
</TabItem>
</Tabs>
```json title="Result"
{
"bytes": 2114023,
"filepath": "/tmp/tqjp5wvc.gbl.bin",
"result": true,
"close_connection": {
"result": true
}
}
```