Пример #1
0
 public static void Main()
 {
       ManualResetEvent wait = new ManualResetEvent(false);
       AsynchronousFtpUpLoader uploader = new AsynchronousFtpUpLoader(wait);
       uploader.AllowAbortUpload("out.txt", "ftp://sharriso1/ftptests.txt");
       wait.WaitOne();
       if (uploader.AsyncException != null)
       {
             Console.WriteLine(uploader.AsyncException.ToString());
       }
 }
Пример #2
0
        public bool transmissao(string arquivo, string pdv, string ip, ref string msg)
        {
            #region
            ftp = new AsynchronousFtpUpLoader();
            string   filename = arquivo;
            FileInfo objFile  = new FileInfo(filename);
            msg = "";

            if (ftp.Main("ftp://" + ip + "/" + objFile.Name, objFile.ToString(), alwaysVariables.Atualizador, alwaysVariables.PalavraChave, ref msg))
            {
                return(true);
            }
            else
            {
                return(false);
            }
            #endregion

            /*
             #region
             *
             * string filename = arquivo;
             *
             * FileInfo objFile = new FileInfo(filename);
             * FtpWebRequest objFTPRequest;
             *
             *  // Create FtpWebRequest object
             *  objFTPRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ip + "/" + arquivo));
             *
             *  // Set Credintials
             *  objFTPRequest.Credentials = new NetworkCredential(alwaysVariables.Atualizador, alwaysVariables.PalavraChave);
             *
             *  if (isValidConnection("ftp://" + ip + "/" + objFile.Name, alwaysVariables.Atualizador, alwaysVariables.PalavraChave))
             *  {
             *      // By default KeepAlive is true, where the control connection is
             *      // not closed after a command is executed.
             *      objFTPRequest.KeepAlive = false;
             *
             *      // Set the data transfer type.
             *      objFTPRequest.UseBinary = true;
             *
             *      // Set content length
             *      objFTPRequest.ContentLength = objFile.Length;
             *
             *      // Set request method
             *      objFTPRequest.Method = WebRequestMethods.Ftp.UploadFile;
             *
             *      // Set buffer size
             *      int intBufferLength = 16 * 1024;
             *      byte[] objBuffer = new byte[intBufferLength];
             *
             *      // Opens a file to read
             *      FileStream objFileStream = objFile.OpenRead();
             *
             *      try
             *      {
             *          // Get Stream of the file
             *          Stream objStream = objFTPRequest.GetRequestStream();
             *
             *          int len = 0;
             *
             *          while ((len = objFileStream.Read(objBuffer, 0, intBufferLength)) != 0)
             *          {
             *              // Write file Content
             *              objStream.Write(objBuffer, 0, len);
             *
             *          }
             *
             *          objStream.Close();
             *          objFileStream.Close();
             *          if(File.Exists(arquivo))
             *          {
             *              File.Delete(arquivo);
             *          }
             *      }
             *      catch (Exception ex)
             *      {
             *          return false;//throw ex;
             *      }
             *      return true;
             *  }
             *  else
             *  {
             *      return false;//throw ex;
             *  }
             *
             #endregion
             */
        }
Пример #3
0
        /*
         * public static async Task<IEnumerable<DtoSistema>> GetDataFromBase(DtoSistema dados)
         * {
         *  await Task.Delay(0);
         *
         *  using (DalSistema restricao = new DalSistema())
         *  {
         *      try
         *      {
         *          return await restricao.SelectObjectsFull(restricao.ComandoSelectFull, dados);
         *      }
         *      catch (Exception)
         *      {
         *          throw;
         *          //await LogSystem.WriteErrorLog($"Erro! Mensagem: {e.Message} | StackTrace: {e.StackTrace}", "BLLUsuario");
         *      }
         *  }
         *  //return null;
         * }*/
        #endregion

        public bool transmissao(string arquivo, string pdv, string ip, ref string msg, bool modo)
        {
            #region
            ftp = new AsynchronousFtpUpLoader();
            string   filename = arquivo;
            FileInfo objFile  = new FileInfo(filename);
            msg = "";

            if (ftp.Main("ftp://" + ip + "/" + objFile.Name, objFile.ToString(), alwaysVariables.Atualizador, alwaysVariables.PalavraChave, ref msg, modo))
            {
                return(true);
            }
            else
            {
                return(false);
            }

            /*
             * msg = "";
             *
             *  // Create FtpWebRequest object
             *  objFTPRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ip + "/" + objFile.Name));
             *
             *  // Set Credintials
             *  objFTPRequest.Credentials = new NetworkCredential(alwaysVariables.Atualizador, alwaysVariables.PalavraChave);
             *
             *
             *
             *  if (isValidConnection("ftp://" + ip + "/" + objFile.Name, alwaysVariables.Atualizador, alwaysVariables.PalavraChave))
             *  {
             *
             *      // By default KeepAlive is true, where the control connection is
             *      // not closed after a command is executed.
             *      objFTPRequest.KeepAlive = false;
             *
             *      // Set the data transfer type.
             *      objFTPRequest.UseBinary = true;
             *
             *      // Set content length
             *      objFTPRequest.ContentLength = objFile.Length;
             *
             *      // Set request method
             *      objFTPRequest.Method = WebRequestMethods.Ftp.UploadFile;
             *
             *      // Set buffer size
             *      int intBufferLength = 16 * 1024;
             *      byte[] objBuffer = new byte[intBufferLength];
             *
             *      // Opens a file to read
             *      FileStream objFileStream = objFile.OpenRead();
             *      /*using (FileStream objFileStream = objFile.OpenRead())
             *      {
             *          objFileStream.Read(objBuffer, 0, Convert.ToInt32(objFile.Length));
             *      }*/
            /*
             *      try
             *      {
             *          using (FtpWebResponse response =
             *                  (FtpWebResponse)objFTPRequest.
             *                                     GetResponse())
             *          {
             *              // Get Stream of the file
             *              using (Stream objStream = objFTPRequest.GetRequestStream())
             *              {
             *
             *                  int len = 0;
             *
             *                  while ((len = objFileStream.Read(objBuffer, 0, intBufferLength)) != 0)
             *                  {
             *                      // Write file Content
             *                      objStream.Write(objBuffer, 0, len);
             *                  }
             *                  objStream.Flush();
             *                  objStream.Close();
             *                  objFileStream.Close();
             *                  objFileStream = null;
             *              }
             *          }
             *          /*FtpWebResponse ftpResponse = (FtpWebResponse)objFTPRequest.GetResponse();
             *          string test = (ftpResponse.StatusDescription);
             *          objFTPRequest.Abort();
             *          ftpResponse.Close();*/
            /*
             *          if(File.Exists(arquivo))
             *          {
             *              File.Delete(arquivo);
             *          }
             *      }
             *      catch (Exception ex)
             *      {
             *          msg = ex.ToString();
             *          return false;//throw ex;
             *      }
             *      return true;
             *  }
             *  else
             *  {
             *      msg = "ERRO DE CONEXÃO COM SERVIDOR - ANALISE DE PARAMETROS: " + "ftp://" + ip + "/" + objFile.Name;
             *      return false;//throw ex;
             *  }
             */
            #endregion
        }