The code I use is the following:
private void enviarSFTP(Filename fileToSend)
{
System.Object ftpo;
System.Object ftpResponse;
System.Net.FtpWebRequest request;
System.IO.StreamReader reader;
System.IO.Stream requestStream;
System.Byte[] bytes;
System.Net.NetworkCredential credential;
System.Text.Encoding utf8;
System.Net.FtpWebResponse response;
System.Exception netExcepn;
FERR_FTP_PagoATerceros configuracionFTP;
int fileCount;
System.Array files;
int i;
str nextFile;
Filename filepath;
Filename fileType, fileNameString;
FileNameType pattern = '*.TXT';
FileName ftpFileName, fileName;
select firstOnly configuracionFTP where configuracionFTP.BankCode == '1';
new InteropPermission(InteropKind::ClrInterop).assert();
try
{
if (fileToSend)
{
[filepath, filename, fileType] = fileNameSplit(fileToSend);
fileNameString = fileName + fileType;
//ftpFileName = 'ftp://' + configuracionFTP.FTPAddress + ':' + configuracionFTP.FTPPort + '/' + configuracionFTP.FTPLocation + '/' + fileNameString;
ftpFileName = 'ftp://' + configuracionFTP.FTPAddress + '/' + configuracionFTP.FTPLocation + '/' + fileNameString;
reader = new System.IO.StreamReader(fileToSend);
utf8 = System.Text.Encoding::get_UTF8();
bytes = utf8.GetBytes(reader.ReadToEnd());
reader.Close();
ftpo = System.Net.WebRequest::Create(ftpFileName);
request = ftpo;
credential = new System.Net.NetworkCredential(configuracionFTP.FTPUser, configuracionFTP.FTPPassword);
request.set_Credentials(credential);
request.set_ContentLength(bytes.get_Length());
request.set_Method("STOR");
requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.get_Length());
requestStream.Close();
ftpResponse = request.GetResponse();
response = ftpResponse;
info(response.get_StatusDescription());
}
}
catch(Exception::CLRError)
{
netExcepn = CLRInterop::getLastException();
error(netExcepn.ToString());
}
CodeAccessPermission::revertAssert();
Apparently the problem is because the code is for an FTP connection and I need an SFTP connection, indicating the type of protocol to use and the SCP delay.