unable to connect - WeOnlyDo Discussion board

unable to connect (wodSFTP / wodSFTP.NET / wodSFTPdll)

by Marcos, Tuesday, July 05, 2005, 15:06 (6874 days ago)

Hi,
I am using WeOnlyDo.Client trial version to connect to a remote server but I have problems.
I am using a library project which uses WeOnlyDo.Client library. When I try to connect there is no error but I think that it doesn't connect bacause when I try to put or get files I get the next error Invalid state. Connect first. Does anyone help me?
this is the code.

using System;
using System.Diagnostics;
using WeOnlyDo.Client;

namespace RepsolYPF.CCSi.TravelClub.CompClaseSFTP
{

[Serializable]
public class ClaseSFTP
{
SFTP sftp1 = new SFTP();

public int Ejecutar (string Tipo, string User, string Pwd, string Server, int Puerto, string PathYFileName, string chdir)
{
try
{
Conectar (Server,Puerto,User,Pwd);

if (Tipo == put )
SubirFichero(chdir,PathYFileName);
else if (Tipo == get )
ObtenerFichero(chdir,PathYFileName);
else
{
Desconectar();
return -1;
}
Console.WriteLine ( Ejecución con exito );
return 0;
}
catch (Exception ex)
{
Console.WriteLine ( No se ha podido ejecutar la operación indicada );
return -1;
}
}

private void Conectar(string Server, int Puerto, string User, string Pwd)
{
try
{
sftp1.Hostname = Server;
sftp1.Login = User;
sftp1.Password = Pwd;
sftp1.Port = Puerto;
sftp1.Connect();
Console.WriteLine( Ha conectado );
}
catch (Exception ex)
{
Console.WriteLine( Error al conectar. +ex.Message);
throw ex;
}
}

private void Desconectar ()
{
try
{
sftp1.Disconnect();
Console.WriteLine( Ha desconectado );
}
catch (Exception ex)
{
Console.WriteLine( Error al desconectar +ex.Message);
throw ex;
}
}

private void ObtenerFichero (string chdir, string PathYFileName)
{
try
{
Error = null;
sftp1.GetFile (chdir,PathYFileName);
Console.WriteLine ( Fichero descargado );
}
catch (Exception ex)
{
Console.WriteLine ( Error al descargar el fichero +ex.Message);
throw ex;
}
}

private void SubirFichero (string chdir, string PathYFileName)
{
try
{
sftp1.PutFile(PathYFileName,chdir);
Console.WriteLine ( Fichero subido );
}
catch (Exception ex)
{
Console.WriteLine ( Error al subir el fichero +ex.Message);
throw ex;
}
}
}
}

Re: unable to connect

by wodSupport, Tuesday, July 05, 2005, 16:09 (6874 days ago) @ Marcos

Marcos,

hi. I think setting Sftp1.Blocking = true will solve your problem. The way you use the component, you don't give it enough time to complete your previous request, since by default component works in async manner.

Hope I helped.

Re: unable to connect

by Marcos, Friday, July 08, 2005, 12:35 (6871 days ago) @ wodSupport

thank you,
it works now.