Пример #1
0
 public void DownloadFile(SFTPDownloadArgument downloadArgument, CallbackContext callbackContext)
 {
     try
     {
         var sftpResult = this.DownloadFile(downloadArgument);
         callbackContext.SendPluginResult(new PluginResult(PluginResult.Status.OK, sftpResult));
     }
     catch (Exception e)
     {
         m_Logger.Error(e);
         callbackContext.Error(new
         {
             type    = "Exception",
             code    = "",
             message = e.Message,
             details = e.StackTrace
         });
     }
 }
Пример #2
0
 public void DownloadFileLegacy(SFTPDownloadArgument downloadArgument, CallbackContext callbackContext)
 {
     try
     {
         var sftpResult = DownloadFile(downloadArgument);
         _sftpClient.Close();
         _sftpClient = null;
         callbackContext.SendPluginResult(new PluginResult(PluginResult.Status.OK, sftpResult));
     }
     catch (Exception ex)
     {
         m_Logger.Error(ex);
         callbackContext.Error(new
         {
             type    = "Exception",
             code    = "",
             message = ex.Message,
             details = ex.StackTrace
         });
     }
 }
Пример #3
0
        private FtpStatusCode DownloadFile(SFTPDownloadArgument downloadArgument)
        {
            m_Logger.Debug($"downloadArgument:{downloadArgument}");
            string[] paths    = downloadArgument.RemotePathWithFileName.Split('/');
            string   fileName = paths[paths.Length - 1];

            Requires.NotNull(downloadArgument, "downloadArgument");
            Requires.NotNullOrEmpty(downloadArgument.RemoteHost, "remoteHost");
            Requires.NotNullOrEmpty(downloadArgument.RemotePathWithFileName, "remotePathWithFileName");
            Requires.NotNullOrEmpty(downloadArgument.LocalPathWithoutFileName, "localPathWithoutFileName");
            Requires.NotNullOrEmpty(downloadArgument.UserName, "userName");
            Requires.NotNullOrEmpty(downloadArgument.Password, "password");
            m_Logger.Debug("本地文件路径:" + downloadArgument.LocalPathWithoutFileName + "\\" + fileName);
            if (File.Exists(downloadArgument.LocalPathWithoutFileName + "\\" + fileName))
            {
                File.Delete(downloadArgument.LocalPathWithoutFileName + "\\" + fileName);
            }
            _sftpClient = GetInstance(downloadArgument.RemoteHost, downloadArgument.UserName, downloadArgument.Password);
            var sftpResult = _sftpClient.DownloadFile(downloadArgument.RemotePathWithFileName, downloadArgument.LocalPathWithoutFileName);

            return(sftpResult);
        }