0

我写了下面的代码。但此代码不可用...

当我执行时,发生。如果有人知道什么,请给我建议...提前谢谢。


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);

}

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

错误发生在以下地方...

---------------------------------------------------------
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, "");

}

}
4

2 回答 2

1

当前的 NuGet 包仍然是1.1.1.13不包含该Rename方法的版本。如果包维护者可以更新它,那就太好了。

但与此同时,如果其他人需要使用当前的 NuGet 包,这里有一个基于反射的扩展方法解决方案。不好,但至少我可以在不分叉/重建等的情况下使用该包。

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);
}
于 2016-02-22T16:24:17.227 回答
0

我添加了你的

public void Rename(string oldPath, string newPath)
{

   SftpChannel.rename(oldPath, newPath);

}

将代码放入 Sftp.cs 类中,我将其命名为:

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

然后它成功重命名了我的文件。顺便说一句谢谢

于 2012-02-14T08:13:05.367 回答