This project is read-only.

Using ChangeDirectory

Mar 26, 2012 at 6:36 PM
Edited Mar 26, 2012 at 7:12 PM

Hello,

I am trying to use the Sftp.ChangeDirectory call in order to change to a directory for an UploadFile operation, then to change back to the root ftp directory directory. However, I haven't found a way to do this. I tried using ChangeDirectory(".") and ChangeDirectory(".."), but it will just timeout after a period of time.

I know one workaround is it reinstantiate the SftpClient object, but I'd rather not do that. I've looked over documentation and the discussions to see if I could find any information on this but I was unable to find anything. Can anyone help me out? For example:

 

if (!m_oClient.IsConnected)
    m_oClient.Connect();

m_oClient.ChangeDirectory("ftpfiles");

FileStream oInput = new FileStream(LocalDirectory + LocalFile, FileMode.Open, FileAccess.ReadWrite);
m_oClient.UploadFile(oInput, RemoteFile);
 oInput.Close();

//back to root ftp directory
m_oClient.ChangeDirectory("???");

 

 

Mar 27, 2012 at 7:58 PM
Edited Mar 27, 2012 at 8:57 PM

I found the issue.

Ignore the code above... in the "real" situation I am using this in, I Sftp.Connect() then Sftp.Disconnect(), then in another function I Sftp.Connect() again if Sftp.IsConnected is set to false. However, there is something wrong with the Sftp.IsConnected property. It is set to true when I run Sftp.Connect(), but it is not set to false when I run Sftp.Disconnect().

By the way, I am using the 3.5 build of the code.