Professional Documents
Culture Documents
can you give me an example for apex code integration (without using any other client, directly
between Salesforce and SFTP)
ANSWER
public class SFTPIntegration {
req.setMethod('GET');
req.setHeader('Content-Type', 'text/plain');
req.setBody(ftpCommand);
req.setTimeout(120000);
if (res.getStatusCode() != 200) {
System.debug('Failed to transfer file. Status code: ' + res.getStatusCode() + ', message: ' +
res.getStatus());
} else {
// do something with the file content, such as insert into a custom object
attachment.Name = 'file.txt';
attachment.Body = fileContent;
attachment.ParentId = 'your_record_id';
insert attachment;
}
SFTPIntegration.transferFile();
public class SFTPIntegration {
req.setMethod('GET');
req.setHeader('Content-Type', 'text/plain');
req.setBody(ftpCommand);
req.setTimeout(120000);
if (res.getStatusCode() != 200) {
System.debug('Failed to transfer file. Status code: ' + res.getStatusCode() + ', message: ' +
res.getStatus());
} else {
// do something with the file content, such as insert into a custom object
attachment.Name = 'file.txt';
attachment.Body = fileContent;
attachment.ParentId = 'your_record_id';
insert attachment;
}
}