2
I am trying to upload files via FTP (TLS), but I am not successful because it always returns an error when my code runs "Connect()". I have tried using Ftpwebrequest , Ftpclient, Tamir.Sharpssh and Sftpclient. Any of them during the "Connect()" instruction I get a connection failure message, follow detail:
a) Connect with SFTP classes 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", for 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 passaword. I do not need to inform key or certificate and connect normally. So, I do not have clarity of what is occurring.
Should I or should I not use a key/certificate to connect? Even Filizila does not need this...
Obs.Framework 4.5.2
Thanks in advance.
Yes, no doubt it will be relevant Cleber! Then you can accept your own answer to your question.
– George Wurthmann