2013-02-14 90 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 
       } 
      } 
     }