NOTE: This page has been translated automatically from Russian to English. Original page.
Example of downloading / uploading files to a SFTP server from 1C
Unfortunately 1C does not allow their funds to exchange files with SFTP server.
Faced with this problem, the best for himself chose the option of using a free SFTP client: WinSCP.
I have not found work in a network of examples 1C with this utility via COM-connection, so its spread. Perhaps someone will be useful.
Faced with this problem, the best for himself chose the option of using a free SFTP client: WinSCP.
I have not found work in a network of examples 1C with this utility via COM-connection, so its spread. Perhaps someone will be useful.
First step is to download the installation package (you can also use a portable-version) and COM-library site WinSCP and register it:
% WINDIR% \ Microsoft.NET \ Framework \ version \ RegAsm.exe WinSCP.dll / codebase / tlb
Learn more about setting here
Now you can work with it from 1C:
//COMPOUND
Attempt
// Set the connection settings
sessionOptions = New COMObekt ( "WinSCP.SessionOptions"); // Create an object SessionOptions
sessionOptions.HostName = "example.com";
sessionOptions.UserName = "user";
sessionOptions.Password = "mypassword";
sessionOptions.SshHostKeyFingerprint = "ssh-rsa 1024 xx: xx: xx: xx: xx: xx: xx: xx: xx: xx: xx: xx: xx: xx: xx: xx";
session = New COMObekt ( "WinSCP.Session"); // Create a Session object
// Parameter must be used if the path register DLL and executable are different
session.ExecutablePath = "C: \ Program Files (x86) \ WinSCP \ winscp.exe";
// connect
session.Open (sessionOptions);
An exception
Report (OpisanieOshibki ());
Return;
KonetsPopytki;
//UNLOADING
Attempt
PutVygruzki Obekt.KatalogVygruzki + = '*';
PutZagruzkiNaFTP = Obekt.KatalogZagruzkiNaFTPServere;
// Upload files
transferResult = session.PutFiles (PutVygruzki, PutZagruzkiNaFTP);
// Check the result for errors
transferResult.Check ();
// Process the result of unloading
For each VygruzhennyyFayl From transferResult.Transfers Cycle
Report ( "Unloaded file:" + VygruzhennyyFayl.FileName);
PeremestitFayl (VygruzhennyyFayl.FileName, HranilischeVygruzhennyhFaylov);
KonetsTsikla;
An exception
Report (OpisanieOshibki ());
KonetsPopytki;
//LOADING
Attempt
PutZagruzki Obekt.KatalogZagruzki = + "\ *";
PutVygruzkiNaFTP = Obekt.KatalogVygruzkiNaFTPServere;
// Load files from a remote server
transferResult = session.GetFiles (PutVygruzkiNaFTP, PutZagruzki);
// Check errors
transferResult.Check ();
// Process the results
For each ZagruzhennyyFayl From transferResult.Transfers Cycle
Report ( "Uploaded file:" + ZagruzhennyyFayl.FileName);
session.RemoveFiles (ZagruzhennyyFayl.FileName); // Remove the already downloaded files
KonetsTsikla;
An exception
Report (OpisanieOshibki ());
KonetsPopytki;
// Deactivate the connection
session.Dispose ();
All the necessary files and an example of sharing the attachment processing.
I gave an example of just the basic features that he used. The library is quite a lot of classes and methods, and can be greatly expanded with the need to use opportunities. The manual here