2011-09-15 5 views
0

다음 코드와 같이 작성했습니다. 하지만이 코드를 사용할 수 없습니다 ...sharpssh를 사용하여 원격 파일의 이름을 바꿀 수 없습니다

내가 실행할 때 발생합니다. 누군가가 뭔가를 아는 경우 나에게 충고 pls을 제공하십시오 ... 미리 감사드립니다. 오류는 다음과 같은 장소를 발생


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

} 

} 

답변

0

나는 Sftp.cs 클래스로

public void Rename(string oldPath, string newPath) 
{ 

    SftpChannel.rename(oldPath, newPath); 

} 

코드를 추가하고 나는 그것이라고 :

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

내 파일의 이름이 성공적으로 변경되었습니다. 방법을 이용해주세요.

+1

를 사용할 수 없음 -> http://bitbucket.org/mattgwagner/sharpssh을 – MattGWagner

1

현재 NuGet 패키지는 메서드가없는 버전 1.1.1.13입니다. 패키지 유지 관리자가 업데이트 할 수 있다면 좋을 것입니다.

그러나 현재 NuGet 패키지로 다른 사람이 필요로하는 경우 여기에 반사 기반 확장 방법 솔루션이 있습니다. 좋은,하지만 적어도 나뿐만 아니라 SFTP에 내가 SftpChannel에서 이름 바꾸기 방법을 버블 등 재건/분기없이 패키지,

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); 
} 
관련 문제