I'm trying to upload files via FTP (TLS), but I'm not successful because it always returns an error when my code executes "Connect ()". I have already tried using the FtpWebRequest, FtpClient, Tamir.SharpSsh, and SftpClient classes. Any of them during the "Connect ()" statement get a connection failure message, it follows detail:
a) Connect with classes to SFTP Example:
private void UploadSFTPFile(string host, string username, string
password, string sourcefile, string destinationpath, string port)
{
int port2 = Convert.ToInt32(port);
try
{
using (SftpClient client = new SftpClient(host, port2, username, password))
{
client.Connect(); //o erro ocorre aqui!!
client.ChangeDirectory(destinationpath);
using (FileStream fs = new FileStream(sourcefile, FileMode.Open))
{
try
{
client.BufferSize = 4 * 1024;
client.UploadFile(fs, Path.GetFileName(sourcefile));
Global.retorno = "Envio via SFTP " + host + " efetuado com sucesso.";
}
catch (Exception ex)
{
Global.retorno = "Erro no envio do arquivo via SFTP (1)" + host + ". Detalhe: " + ex;
}
}
}
}
catch (Exception ex)
{
Global.retorno = "Erro na conexão via SFTP (2)" + host + ". Detalhe: " + ex;
}
}
Error Message: "A connection attempt failed because the connected component did not respond correctly after a period of time or the established connection failed because the connected host did not respond ..."
IMPORTANT: I also tried to use the class / library "WinSCP", in this case I had the following return message: "Connection failed. Authentication failed. Connection failed. TLS required".
The strange thing is that with FileZila I connect without problems informing the host, userName and pasaword. I do not need to enter a key or certificate and I connect normally. So I'm not clear about what's happening.
Should I use a key / certificate to connect? Even Filizila does not need this ...
Obs.Framework 4.5.2
Thank you in advance.