0

i wrote like the following code. but this code is not available...

when i execute, occur. if anyone knows something, give me advice pls... thanks in advance.


void sftp_OnTransferEnd(string src, string dst, int transferredBytes
                          , int totalBytes, string message)
{

    if (sftp == null)
{
sftp = new Sftp(Const.SFTP_HOST, Const.SFTP_USER, Const.SFTP_PASSWORD);

sftp.Connect();

}

SftpChannel.rename("file/123_Uploading.zip", "file/123_Finished.zip");
}


--------------------------------------------
Sftp.cs

public void Rename(string oldPath, string newPath)
{

   SftpChannel.rename(oldPath, newPath);

}

---------------------------------------------

Error occur the following place...

---------------------------------------------------------
ChannelSftp.cs

public void rename(String oldpath, String newpath)
{

・

・

・


int i=buf.getInt(); << i == 4

if(i==SSH_FX_OK) return;

throwStatusError(buf, i); << throw error

catch(Exception e)

{

if(e is SftpException) throw (SftpException)e; << thrown error (id >> 4, message >> Failure)

throw new SftpException(SSH_FX_FAILURE, "");

}

}
Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
Yamachan
  • 71
  • 1
  • 2
  • 10

2 Answers2

1

The current NuGet package is still of version 1.1.1.13 which does not contain the Rename method. It would be great if the package maintainer could update it.

But in the meantime if anyone else needs it with the current NuGet package, here is a Reflection-based extension method solution. Not nice, but at least I can use the package without forking/rebuilding, etc.

public static void Rename(this Sftp client, string oldName, string newName) {
  var channelProperty = client.GetType().GetProperty("SftpChannel", BindingFlags.NonPublic | BindingFlags.Instance);
  channelProperty.GetValue(_client, null).CastTo<ChannelSftp>().rename(OldName, newName);
}
Zoltán Tamási
  • 12,249
  • 8
  • 65
  • 93
0

I added your

public void Rename(string oldPath, string newPath)
{

   SftpChannel.rename(oldPath, newPath);

}

code into Sftp.cs class and I called it :

  var sftp = new Sftp("sftp.example.com", username, password);
  sftp.Connect(22);
  sftp.Rename(oldValue, newValue);
  sftp.Close();

then it renamed my file successfully.Thanks by the way

user741319
  • 625
  • 3
  • 9
  • 18