Ejemplo n.º 1
0
        public void Execute(Arguments arguments)
        {
            ListStructure cmdresult = new ListStructure();

            try
            {
                if (arguments.directory.Value == null)
                {
                    arguments.directory.Value = String.Empty;
                }
                ftpRequest             = (FtpWebRequest)FtpWebRequest.Create("ftp://" + FtpSettings.GetInstance().Host + "/" + arguments.directory.Value);
                ftpRequest.Credentials = new NetworkCredential(FtpSettings.GetInstance().User, FtpSettings.GetInstance().Password);
                ftpRequest.UseBinary   = FtpSettings.GetInstance().UseBinary;
                ftpRequest.UsePassive  = FtpSettings.GetInstance().UsePassive;
                ftpRequest.KeepAlive   = FtpSettings.GetInstance().KeepAlive;

                ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                ftpResponse       = (FtpWebResponse)ftpRequest.GetResponse();
                ftpStream         = ftpResponse.GetResponseStream();
                StreamReader ftpReader    = new StreamReader(ftpStream);
                string       directoryRaw = ftpReader.ReadToEnd();

                ftpReader.Close();
                ftpStream.Close();
                ftpResponse.Close();
                ftpRequest = null;

                string[] list = directoryRaw.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (String line in list)
                {
                    string[] items = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    string   fn    = items.Last();
                    bool     isDir = items[0].StartsWith("d", StringComparison.InvariantCultureIgnoreCase);
                    String   s     = new FtpListingItem(fn, isDir).ToString();
                    cmdresult.Value.Add(new TextStructure(s));
                }
                Scripter.Variables.SetVariableValue(arguments.Result.Value, new ListStructure(cmdresult));
            }
            catch (Exception exc)
            {
                throw new ApplicationException($"Error occured while list directory", exc);
            }
            return;
        }
 public void Execute(Arguments arguments)
 {
     try
     {
         ftpRequest             = (FtpWebRequest)FtpWebRequest.Create("ftp://" + FtpSettings.GetInstance().Host + "/" + arguments.remotefile.Value);
         ftpRequest.Credentials = new NetworkCredential(FtpSettings.GetInstance().User, FtpSettings.GetInstance().Password);
         ftpRequest.UseBinary   = FtpSettings.GetInstance().UseBinary;
         ftpRequest.UsePassive  = FtpSettings.GetInstance().UsePassive;
         ftpRequest.KeepAlive   = FtpSettings.GetInstance().KeepAlive;
         ftpRequest.Method      = WebRequestMethods.Ftp.DeleteFile;
         ftpResponse            = (FtpWebResponse)ftpRequest.GetResponse();
         ftpResponse.Close();
         ftpRequest = null;
     }
     catch (Exception exc) {
         throw new ApplicationException($"Error occured while delete ftp file", exc);
     }
     return;
 }
Ejemplo n.º 3
0
        public void Execute(Arguments arguments)
        {
            try
            {
                ftpRequest             = (FtpWebRequest)FtpWebRequest.Create("ftp://" + FtpSettings.GetInstance().Host + "/" + arguments.remotefile.Value);
                ftpRequest.Credentials = new NetworkCredential(FtpSettings.GetInstance().User, FtpSettings.GetInstance().Password);
                ftpRequest.UseBinary   = FtpSettings.GetInstance().UseBinary;
                ftpRequest.UsePassive  = FtpSettings.GetInstance().UsePassive;
                ftpRequest.KeepAlive   = FtpSettings.GetInstance().KeepAlive;
                ftpRequest.Method      = WebRequestMethods.Ftp.GetDateTimestamp;

                using (FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse())
                {
                    Scripter.Variables.SetVariableValue(arguments.Result.Value, new DateTimeStructure(response.LastModified));
                }

                ftpRequest = null;
                return;
            }
            catch (Exception exc)
            {
                throw new ApplicationException($"Error occured while get file timestamp: " + exc.Message);
            }
        }
Ejemplo n.º 4
0
        public void Execute(Arguments arguments)
        {
            try
            {
                ftpRequest             = (FtpWebRequest)FtpWebRequest.Create("ftp://" + FtpSettings.GetInstance().Host + "/" + arguments.remotefile.Value);
                ftpRequest.Credentials = new NetworkCredential(FtpSettings.GetInstance().User, FtpSettings.GetInstance().Password);
                ftpRequest.UseBinary   = FtpSettings.GetInstance().UseBinary;
                ftpRequest.UsePassive  = FtpSettings.GetInstance().UsePassive;
                ftpRequest.KeepAlive   = FtpSettings.GetInstance().KeepAlive;
                ftpRequest.Method      = WebRequestMethods.Ftp.UploadFile;
                ftpStream = ftpRequest.GetRequestStream();
                FileStream localFileStream = new FileStream(arguments.localfile.Value, FileMode.Open);
                byte[]     byteBuffer      = new byte[bufferSize];
                int        bytesSent       = localFileStream.Read(byteBuffer, 0, bufferSize);

                while (bytesSent != 0)
                {
                    ftpStream.Write(byteBuffer, 0, bytesSent);
                    bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
                }

                localFileStream.Close();
                ftpStream.Close();
                ftpRequest = null;
            }
            catch (Exception exc)
            {
                throw new ApplicationException($"Error occured while sending file to FTP server", exc);
            }
            return;
        }
Ejemplo n.º 5
0
 public void Execute(Arguments arguments)
 {
     try
     {
         ftpRequest             = (FtpWebRequest)FtpWebRequest.Create("ftp://" + FtpSettings.GetInstance().Host + "/" + arguments.remotefile.Value);
         ftpRequest.Credentials = new NetworkCredential(FtpSettings.GetInstance().User, FtpSettings.GetInstance().Password);
         ftpRequest.UseBinary   = FtpSettings.GetInstance().UseBinary;
         ftpRequest.UsePassive  = FtpSettings.GetInstance().UsePassive;
         ftpRequest.KeepAlive   = FtpSettings.GetInstance().KeepAlive;
         ftpRequest.Method      = WebRequestMethods.Ftp.GetFileSize;
         ftpResponse            = (FtpWebResponse)ftpRequest.GetResponse();
         long size = ftpResponse.ContentLength;
         if (ftpResponse != null)
         {
             ftpResponse.Close();
         }
         ftpRequest = null;
         Scripter.Variables.SetVariableValue(arguments.Result.Value, new FloatStructure(size));
         return;
     }
     catch (Exception exc)
     {
         throw new ApplicationException($"Error occured while get file size: " + exc.Message);
     }
 }
Ejemplo n.º 6
0
 static FtpSettings()
 {
     instance = new FtpSettings();
 }