2012-07-31 1 views
0

C#의 한 원격 서버에서 다른 원격 서버로 대용량 파일 (20GB +)을 다운로드해야합니다. 우리는 이미 다른 파일 조작을 위해 ssh 연결을합니다. 바이너리 모드에서 ssh 세션으로부터 ftp 다운로드를 시작해야합니다 (이것은 특정 형식으로 파일을 전달하기위한 원격 서버 요구 사항입니다). 질문 - 자격 증명과 연결하고 모드를 'bin'으로 설정하기 위해 ssh 세션에서 ftp 명령을 보내려면 어떻게해야합니까? 사용하여 SSH를 다음의 기본적으로 해당 :C# - 한 원격 서버에서 다른 서버로 ssh를 통해 ftp를 사용하여 파일 다운로드

FtpWebRequest request =(FtpWebRequest)WebRequest.Create(
     @"ftp://xxx.xxx.xxx.xxx/someDirectory/someFile"); 

request.Credentials = new NetworkCredential("username", "password"); 
request.UseBinary = true; 
request.Method = WebRequestMethods.Ftp.DownloadFile; 

FtpWebResponse response = (FtpWebResponse)request.GetResponse(); 

답변

1

SSH는이 당신이 그것을 실행 명령 줄 것을에서 확인 cmd 만든처럼 이것은 "쉘을 고정"입니다. FTP가 아닙니다. SSH는 FTP 유틸리티 또는 응용 프로그램을 실행할 수 있습니다.

SSH에는 SFTP (또는 SSH File Transfer Protcol)라고하는 항목이 있지만이를 수행하기 위해 .NET에 내장 된 것이 없습니다 (예 : BCL). FtpWebRequest은 SFTP를 지원하지 않습니다.

"FTP"를 공유 함에도 불구하고 그들은 서로 다른 프로토콜이며 서로 호환되지 않습니다.

FTP 다운로드를 시작하려면 SSH에 일종의 유틸리티를 실행하도록 알려야합니다. SFTP 전송을 시작하려면 sftp 명령을 실행할 수 있습니다. 그러나 다른 쪽 끝은 sftp를 지원해야합니다. 또는 scp 명령 (보안 복사)을 실행합니다. 하지만 다시 말하면, 다른 쪽은 그 프로토콜을 지원할 필요가있을 것입니다. (SFTP와 FTP와는 다른 것입니다 ...)

다른 쪽 끝을 쓰려면 SFTP를 수행하는 타사 라이브러리를 찾아야합니다 또는 SCP ...

+0

귀하의 회신에 감사드립니다. 앞서 언급했듯이 우리는 이미 SSH (C# 서비스에서 유닉스 박스에 연결)를 사용하여 많은 파일 작업을 수행하고 있습니다. 원격 서버의 파일은 특정 자격 증명으로 ftp 연결을 만들 때만 필요한 형식으로 제공됩니다. sftp를 지원하지 않습니다. 대부분 ssh 명령 (ssh 연결은 웹 서비스에서 시작됨)에서 ftp를 사용하여 파일을 다운로드하기 위해 배치 파일을 실행하는 아이디어가 있습니다. – user1408552

0

Chilkat Chilkat from ChilkatSoft (면책 조항 : 나는 회사에 가입하지 않고 방금 유료 사용자입니다.)

Chilkat.SFtp sftp = new Chilkat.SFtp(); 

// Any string automatically begins a fully-functional 30-day trial. 
bool success; 
success = sftp.UnlockComponent("Anything for 30-day trial"); 
if (success != true) { 
    MessageBox.Show(sftp.LastErrorText); 
    return; 
} 

// Set some timeouts, in milliseconds: 
sftp.ConnectTimeoutMs = 5000; 
sftp.IdleTimeoutMs = 10000; 

// Connect to the SSH server. 
// The standard SSH port = 22 
// The hostname may be a hostname or IP address. 
int port; 
string hostname; 
hostname = "www.my-ssh-server.com"; 
port = 22; 
success = sftp.Connect(hostname,port); 
if (success != true) { 
    MessageBox.Show(sftp.LastErrorText); 
    return; 
} 

// Authenticate with the SSH server. Chilkat SFTP supports 
// both password-based authenication as well as public-key 
// authentication. This example uses password authenication. 
success = sftp.AuthenticatePw("myLogin","myPassword"); 
if (success != true) { 
    MessageBox.Show(sftp.LastErrorText); 
    return; 
} 

// After authenticating, the SFTP subsystem must be initialized: 
success = sftp.InitializeSftp(); 
if (success != true) { 
    MessageBox.Show(sftp.LastErrorText); 
    return; 
} 

// Open a file on the server: 
string handle; 
handle = sftp.OpenFile("hamlet.xml","readOnly","openExisting"); 
if (handle == null) { 
    MessageBox.Show(sftp.LastErrorText); 
    return; 
} 

// Download the file: 
success = sftp.DownloadFile(handle,"c:/temp/hamlet.xml"); 
if (success != true) { 
    MessageBox.Show(sftp.LastErrorText); 
    return; 
} 

// Close the file. 
success = sftp.CloseHandle(handle); 
if (success != true) { 
    MessageBox.Show(sftp.LastErrorText); 
    return; 
} 
관련 문제