2015-05-14 63 views
0

我試圖從遠程服務器使用OpenNETCF.ftp類 文件大小96KB 同時打開它,我得到一個錯誤的FTP下載一些文件說,損壞的文件文件損壞當使用OpenNETCF.Ftp

private static int BUFFER_SIZE = 512; 
private static int DEFAULT_PORT = 21; 

private bool    m_connected  = false; 
private FTPMode    m_mode   = FTPMode.Passive; 
private int     m_port = DEFAULT_PORT; 
private string    m_host   = ""; 
private FTPTransferType m_type = FTPTransferType.Binary; 
private string    m_uid   = ""; 
private string    m_pwd   = ""; 
private Socket    m_cmdsocket  = null; 
private bool    m_exceptions = true; 
private byte[]    m_buffer  = new byte[BUFFER_SIZE]; 
private FTPServerType  m_server = FTPServerType.Unknown; 

public void GetFile(string remoteFileName, string localFileName, bool overwrite) 
{ 
    int bytesrecvd = 0; 
    using (var output = File.Create(localFileName)) 
    using (var socket = OpenDataSocket()) 
    { 
     response = SendCommand("RETR " + remoteFileName); 
     if (!((response.ID == StatusCode.FileStatusOK) || (response.ID == StatusCode.ConnectionAlreadyOpen))) 
     { 
      if (!m_exceptions) 
      { 
       return; 
      } 
      else 
      { 
       throw new IOException(response.Text); 
      } 
     } 

    while (true) 
    { 
     bytesrecvd = socket.Receive(m_buffer,m_buffer.Length, 0); 
     output.Write(m_buffer, 0, bytesrecvd); 
     response.Text = bytesrecvd.ToString(); 
     if (bytesrecvd <= 0) 
     { 
      break; 
     } 
    } 
} 
+1

什麼是錯誤? –

+0

exe文件不能win32應用程序 – xfiles

回答

0

很可能你沒有設置傳輸的二進制模式,並且默認情況下它被設置爲ASCII。 您需要發出'TYPE I'命令。