2013-02-14 66 views
0

我想用sftp將文件上傳到服務器。我已經下載並安裝了奇爾卡特,我正在下載文件沒有任何問題。但是當我嘗試將文件上傳到服務器時,我收到沒有錯誤說明上傳文件。當我檢查響應消息時,它說「文件上傳成功1」,其中一個是true但是這些文件沒有上傳到服務器。使用Chilkat上傳文件的問題

這是我的代碼:

public void UploadAndMoveFile() 
     { 
      bool success = false; 
      string path = @"\\geodis\"; 
      string archive = @"\\Archive\"; 
      string[] files = Directory.GetFiles(path); 
      if (files.Count() == 0) 
      { 
//no files 
      } 

      foreach (string file in files) 
      { 
       string fileName = Path.GetFileName(file); 
       string fileSource = path + fileName; 
       string fileDestination = archive + fileName; 
       string handle; 
       string ftp = @"\IN\"+fileName; 
       handle = sftp.OpenFile(ftp, "writeOnly", "createTruncate"); 
       if (handle == null) 
       { 
        Console.WriteLine(sftp.LastErrorText); 
        return; 
       } 
       success = sftp.UploadFile(handle, fileSource); 
       if (success == true) 
       { 
        AppendLogFile("Uploading File Succeeded", "Uploade File", fileName); 
        System.IO.File.Move(fileSource, fileDestination); 
        AppendLogFile("Moving File Succeeded", "Moving File", fileName); 
       } 
       else 
       { 
        // no files 
       } 
      } 
     } 

誰能幫我找出我做錯了嗎?

回答

0

找到了問題,在上傳方法我有處理變量,而不是ftp變量。

這裏是解決方案:

public void UploadAndMoveFile() 
     { 
      bool success = false; 
      string path = @"\\geodis\"; 
      string archive = @"\\Archive\"; 
      string[] files = Directory.GetFiles(path); 
      if (files.Count() == 0) 
      { 
//no files 
      } 

      foreach (string file in files) 
      { 
       string fileName = Path.GetFileName(file); 
       string fileSource = path + fileName; 
       string fileDestination = archive + fileName; 
       string handle; 
       string ftp = @"\IN\"+fileName; 
       handle = sftp.OpenFile(ftp, "writeOnly", "createTruncate"); 
       if (handle == null) 
       { 
        Console.WriteLine(sftp.LastErrorText); 
        return; 
       } 
       success = sftp.UploadFile(ftp, fileSource); 
       if (success == true) 
       { 
        AppendLogFile("Uploading File Succeeded", "Uploade File", fileName); 
        System.IO.File.Move(fileSource, fileDestination); 
        AppendLogFile("Moving File Succeeded", "Moving File", fileName); 
       } 
       else 
       { 
        // no files 
       } 
      } 
     }