2012-11-21 4 views
0

SSH 명령 실행 및 파일 업로드를 기존 응용 프로그램에 추가하고 있습니다. 서로 다른 무료 라이브러리와 라이센스 라이브러리를 비교 한 결과, http://code.google.com/p/ssh2-net/을 사용하기로 결정했기 때문에 C#에 대한 JAVA 라이브러리의 포트로 보인다. 우리는 이미 JAVA 버전에 대한 좋은 경험을 가지고 있습니다 ...C# 응용 프로그램에서 ch.ethz.ssh2 사용

파일 업로드가 아주 성공적이지 않습니다 ... 아무도 도와 줄 수 있습니까? 이 주석에서 언급 한 바와 같이 나는

Connection conn = StartConnection();  
// --> conn checked and is open! 

Session session = conn.openSession(); 
session.execCommand("sudo mount -o remount,rw /"); 
// --> no error 

SFTPv3Client client = new SFTPv3Client(conn); 
// --> this throws error "Cannot access a closed Stream." 

SFTPv3FileHandle handle = client.createFile("/tmp/" + sshSource.Name); 

using (StreamReader sr = new StreamReader(sshSource.FullName)) 
{ 
    char[] buffer = new char[1024]; 
    int offset = 0; 

    while (sr.Peek() >= 0) 
    { 
     int i = sr.Read(buffer, offset, buffer.Length); 

     byte[] bytes = new byte[1024]; 
     for (int j = 0; j < 1024; j++) 
      bytes[j] = (byte) buffer[j]; 

     client.write(handle, offset, bytes, 0, i); 
     offset += i; 
    } 
} 

을 발견 샘플의 일부 비트의 조합 내 코드입니다, 이미 클라이언트가 SFTPv3Client 클라이언트 = 새로운 SFTPv3Client (CONN) 정의 된 행에 오류가;

덕분에 사전에 어떤 도움을 많이, 프랭크

답변

0

는 SharpSsh로 전환하고 C#

http://www.tamirgal.com/blog/page/SharpSSH.aspx

SshTransferProtocolBase tx = new Scp(_hostname, _username, _password); 
SshExec exec = new SshExec(_hostname, _username, _password); 

tx.Connect(); 
exec.Connect(); 

exec.RunCommand("sudo mount -o remount,rw /"); 
exec.RunCommand("sudo rm /tmp/" + Path.GetFileName(sshTarget)); 
tx.Put(sshSource.FullName, "/tmp/" + Path.GetFileName(sshTarget)); 
을위한 더 나은 (쉽게) 솔루션이 될 것 같다