Skip to main content

Save file

Saves the file from the server to the specified path

Function SaveFile(Val Connection, Val Path, Val FileName) Export

ParameterCLI optionTypeRequiredDescription
Connection--connArbitraryExisting connection or connection configuration
Path--pathStringPath to file on server
FileName--fileStringPath to save file on disk
Returns

Map Of KeyAndValue - Processing result

1C:Enterprise/OneScript code example
Host = "172.33.0.13";
Port = "2222";

UseProxy = True;
ProxySettings = Undefined;
AuthorizationType = "By login and password";

If AuthorizationType = "By login and password" Then

Login = "bayselonarrend";
Password = "12we...";

SFTPSettings = OPI_SFTP.GetSettingsLoginPassword(Host, Port, Login, Password);

ElsIf AuthorizationType = "By key" Then

Login = "bayselonarrend";
PrivateKey = "./ssh_key";
PublicKey = "./ssh_key.pub";

SFTPSettings = OPI_SFTP.GetSettingsPrivateKey(Host, Port, Login, PrivateKey, PublicKey);

ElsIf AuthorizationType = "Keyboard interactive" Then

Login = "bayselonarrend";
Password = "12we...";

AnswersArray = New Array;
AnswersArray.Add(Password);

SFTPSettings = OPI_SFTP.GetSettingsKI(Host, Port, Login, AnswersArray);

Else

Login = "bayselonarrend";
SFTPSettings = OPI_SFTP.GetSettingsViaAgent(Host, Port, Login);

EndIf;

If UseProxy Then

ProxyType = "http"; // http, socks5, socks4

ProxyAddress = "127.0.0.1";
ProxyPort = "8071";
ProxyLogin = "proxyuser";
ProxyPassword = "12we...";

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;
# 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':'keyboard_interactive','host':'172.33.0.34','key_path':null,'keyboard_responses':['12we3456!2154'],'passphrase':null,'password':null,'port':'2223','pub_path':null,'username':'bayselonarrend'}}" \
--path "pic_from_disk.png" \
--file "/tmp/dbqoopd2.khu.bin"
Result
{
"bytes": 2114023,
"filepath": "/tmp/mj0svjpq.wwn.bin",
"result": true,
"close_connection": {
"result": true
}
}