WeOnlyDo.Exceptions.SFTP.InvalidStateException: In (wodSFTP / wodSFTP.NET / wodSFTPdll)
I'm receiving WeOnlyDo.Exceptions.SFTP.InvalidStateException: Invalid state. Not connected. error at sftp1.GetFile method using the code below for sftp.
Could you please let me know what I'm doing wrong ?
=====================================================================
WeOnlyDo.Client.SFTP sftp1 = new WeOnlyDo.Client.SFTP();
WeOnlyDo.Security.Cryptography.KeyManager key1 = new WeOnlyDo.Security.Cryptography.KeyManager();
sftp1.LicenseKey = my license key ;
key1.Load( c:abc );
sftp1.Authentication = WeOnlyDo.Client.SFTP.Authentications.PublicKey;
sftp1.Hostname = host_name ;
sftp1.Login = login_name ;
sftp1.PrivateKey = key1.PrivateKey(WeOnlyDo.Security.Cryptography.SSHKeyTypes.RSAKey);
Console.Writeline( Load key ok );
sftp1.Connect();
Console.Writeline( Connect ok );
sftp1.RemotePath = /data ;
Console.Writeline( RemotePath ok );
sftp1.GetFile(LocalPath, filename);
sftp1.Disconnect();
key1.Dispose();
sftp1.Dispose();
Re: WeOnlyDo.Exceptions.SFTP.InvalidStateException
Puja,
You need to set Blocking Property to true in order to use the component that way. Blocking mode will ensure that the current method is executed before proceeding to the next one.
Please set Blocking proeprty to True before using issuing Connect method. I believe it should work afterwards.
Regards,
Damba
Re: WeOnlyDo.Exceptions.SFTP.InvalidStateException
Puja,
You need to set Blocking Property to true in order to use the component that way. Blocking mode will ensure that the current method is executed before proceeding to the next one.
Please set Blocking proeprty to True before using issuing Connect method. I believe it should work afterwards.
Regards,
Damba
Re: WeOnlyDo.Exceptions.SFTP.InvalidStateException
Puja,
You need to set Blocking Property to true in order to use the component that way. Blocking mode will ensure that the current method is executed before proceeding to the next one.
Please set Blocking proeprty to True before using issuing Connect method. I believe it should work afterwards.
Regards,
Damba
I used the sftp1.blocking property before connect then I recieved a differet error as below
sftp1.Blocking = true;
sftp1.Connect();
System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable network
at ..()
at WeOnlyDo.Client.SFTP.Connect()
Re: WeOnlyDo.Exceptions.SFTP.InvalidStateException
Puja,
What HostName are you trying to connect to? The error means that your machine can't reach the host.
Did you try conencting to that host using any other client? Does that work?
Regards,
Damba
Re: WeOnlyDo.Exceptions.SFTP.InvalidStateException
Puja,
What HostName are you trying to connect to? The error means that your machine can't reach the host.
Did you try conencting to that host using any other client? Does that work?
Regards,
Damba
====================================================================
My connection is working fine now since I was missing the Port number.
Now I'm receiving WeOnlyDo.Exceptions.SFTP.ServerException: Server returned an error: No such file or folder
Do you know what is wrong in below code ?
If my files is stored in xyz folder
and I'm using
filename = abc.text
localpath = .downloads
sftp1.RemotePath = /xyz ;
log.Info( RemotePath ok );
sftp1.GetFile(_Localpath, filename);
Re: WeOnlyDo.Exceptions.SFTP.InvalidStateException
Puja,
You need to provide absolute paths to files for both, local and remote files. I.e:
ftp1.LocalPath = C: ;
ftp1.RemotePath = /home/user/somefile.txt ;
ftp1.GetFile();
or like this:
ftp1.GetFile( C: , /home/user/somefile.txt );
From the code you sent us I see that you're passing wrong values to the component, which causes the error you are receiving.
Regards,
Damba
Re: WeOnlyDo.Exceptions.SFTP.InvalidStateException
Puja,
You need to provide absolute paths to files for both, local and remote files. I.e:
ftp1.LocalPath = C: ;
ftp1.RemotePath = /home/user/somefile.txt ;
ftp1.GetFile();or like this:
ftp1.GetFile( C: , /home/user/somefile.txt );
From the code you sent us I see that you're passing wrong values to the component, which causes the error you are receiving.
Regards,
Damba
===================================================================
Thanks. The above suggesation worked. I have another question. Can I put Getfile method in a loop to retrive multiple files from same directory as an example below
sftp1.LocalPath = C:/Data/xyz ;
foreach (string f in filelist)
{
sftp1.RemotePath = /home/abc/ + f;
sftp1.GetFile();
}
Re: WeOnlyDo.Exceptions.SFTP.InvalidStateException
Hi Puja,
I think you can use multiple GetFile Method call in Blocking mode.
You should change local path to this:
[code]sftp1.LocalPath = C:\Data\xyz ;[/code]
Drazen
Re: WeOnlyDo.Exceptions.SFTP.InvalidStateException
Hi Puja,
I think you can use multiple GetFile Method call in Blocking mode.You should change local path to this:
[code]sftp1.LocalPath = C:\Data\xyz ;[/code]
Drazen
=============================================================
I don't understand what do you mean by blocking mode. I'm already calling sftp1.Blocking = true before connect. Do I need to call that again inside the loop.
Re: WeOnlyDo.Exceptions.SFTP.InvalidStateException
Puja,
When Blocking Property is set to True you are using blocking mode.
You don't need to do anything else.
Drazen