Ejemplo n.º 1
0
        /// <summary>
        /// Convert an FtpItem to a ClientItem
        /// </summary>
        private ClientItem ConvertItem(FtpItem f)
        {
            var fullPath = f.FullPath;

            if (fullPath.StartsWith("./"))
            {
                var cwd = WorkingDirectory;
                var wd  = (controller.Paths.Remote != null && cwd.StartsWithButNotEqual(controller.Paths.Remote) && cwd != "/") ? cwd : controller.GetCommonPath(cwd, false);
                fullPath = fullPath.Substring(2);
                if (wd != "/")
                {
                    fullPath = string.Format("/{0}/{1}", wd, fullPath);
                }
                fullPath = fullPath.Replace("//", "/");
            }

            return(new ClientItem
            {
                Name = f.Name,
                FullPath = fullPath,
                Type = _ItemTypeOf(f.ItemType),
                Size = f.Size,
                LastWriteTime = f.Modified
            });
        }
Ejemplo n.º 2
0
        public static void DailyRun()
        {
            List <ExportItem> runList = CoreDataLibrary.Data.Get.GetDailyRunItems();

            foreach (ExportItem exportItem in runList)
            {
                exportItem.SelectStatementBuilder = SelectStatementBuilder.LoadSelectStatementBuilder(exportItem.ExportItemName);
                CsvDataExporter dataExporter = new CsvDataExporter(@"E:\SteveJ\" + exportItem.ExportItemName + ".csv", exportItem);
                dataExporter.CsvExport();
                if (exportItem.ExportItemFtpId > 0)
                {
                    FtpItem ftpItem = CoreDataLibrary.Data.Get.GetFtpItem(exportItem.ExportItemFtpId);

                    FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
                    request.Method = WebRequestMethods.Ftp.UploadFile;

                    request.Credentials = new NetworkCredential("anonymous", "*****@*****.**");

                    StreamReader sourceStream = new StreamReader("testfile.txt");
                    byte[]       fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                    sourceStream.Close();
                    request.ContentLength = fileContents.Length;

                    Stream requestStream = request.GetRequestStream();
                    requestStream.Write(fileContents, 0, fileContents.Length);
                    requestStream.Close();

                    FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                    Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

                    response.Close();
                }
            }
        }
Ejemplo n.º 3
0
        private ETypeItem GetTypeItem(FtpItem item)
        {
            switch (item.ItemType)
            {
            case FtpItemType.Directory:
                return(ETypeItem.Directory);

            case FtpItemType.File:
                return(ETypeItem.File);

            default:
                switch (item.RawString[0])
                {
                case 'd':
                    return(ETypeItem.Directory);

                case '-':
                    return(ETypeItem.File);

                case 'n':
                    return(ETypeItem.Driver);
                }
                return(ETypeItem.Any);
            }
        }
Ejemplo n.º 4
0
 void OnNewFtpItem(FtpItem item)
 {
     if (null != NewFtpItem)
     {
         NewFtpItem(this, new NewFtpItemEventArgs(item));
     }
 }
Ejemplo n.º 5
0
        private void lvFTPList_DragOver(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(string[])))
            {
                Point        point = lvFTPList.PointToClient(new Point(e.X, e.Y));
                ListViewItem lvi   = lvFTPList.GetItemAt(point.X, point.Y);
                if (lvi != null && e.AllowedEffect == DragDropEffects.Move)
                {
                    if (tempSelected != null && tempSelected != lvi)
                    {
                        tempSelected.Selected = false;
                    }

                    FtpItem file = lvi.Tag as FtpItem;
                    if (file != null && file.ItemType == FtpItemType.Directory)
                    {
                        lvi.Selected = true;
                        tempSelected = lvi;
                        e.Effect     = DragDropEffects.Move;
                    }
                    else
                    {
                        e.Effect = DragDropEffects.None;
                    }
                }
            }
            else if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Move;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
Ejemplo n.º 6
0
 public FtpStorageFolder(FtpItem ftpItem)
 {
     DateCreated = ftpItem.ItemDateCreatedReal;
     Name        = ftpItem.ItemName;
     Path        = ftpItem.ItemPath;
     FtpPath     = FtpHelpers.GetFtpPath(ftpItem.ItemPath);
 }
Ejemplo n.º 7
0
        public static bool FtpFile(FileInfo fileToFtpInfo, ReportLogger reportLogger, ExportItem exportItem)
        {
            int stepId = reportLogger.AddStep();

            try
            {
                if (exportItem.ExportItemFtpId > 0)
                {
                    FtpItem ftpItem = Get.GetFtpItem(exportItem.ExportItemFtpId);

                    string ftpUploadUri = "";
                    if (!ftpItem.FtpAddress.StartsWith(@"ftp://"))
                    {
                        ftpUploadUri = @"ftp://" + ftpItem.FtpAddress.Trim();
                    }
                    else
                    {
                        ftpUploadUri = ftpItem.FtpAddress.Trim();
                    }

                    if (!ftpUploadUri.EndsWith(@"/"))
                    {
                        ftpUploadUri += @"/" + fileToFtpInfo.Name;
                    }
                    else
                    {
                        ftpUploadUri += fileToFtpInfo.Name;
                    }

                    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUploadUri);

                    request.Method = WebRequestMethods.Ftp.UploadFile;

                    request.Credentials = new NetworkCredential(ftpItem.FtpUsername.Normalize(), ftpItem.FtpPassword.Normalize());
                    request.Timeout     = 1800000;

                    FileStream fileStream = new FileStream(fileToFtpInfo.FullName, FileMode.Open, FileAccess.Read);

                    Stream requestStream = request.GetRequestStream();
                    byte[] buffer        = new byte[8092];
                    int    read          = 0;
                    while ((read = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        requestStream.Write(buffer, 0, read);
                    }

                    requestStream.Flush();

                    requestStream.Close();
                }
                reportLogger.EndStep(stepId);
            }
            catch (Exception e)
            {
                reportLogger.EndStep(stepId, e);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 8
0
        internal FtpItem[] EndExecute(IAsyncResult ar)
        {
            AsyncBase.VerifyAsyncResult(ar, typeof(List_SO));
            HandleAsyncEnd(ar, true);

            FtpItem[] ret = new FtpItem[_items.Count];
            _items.CopyTo(ret);
            return(ret);
        }
Ejemplo n.º 9
0
        string FtpItem2Path(FtpItem item)
        {
            if (item.RawString.Length < OffsetFtpItemPath)
            {
                return(string.Empty);
            }
            var dir = item.RawString.Substring(OffsetFtpItemPath);

            return(dir == "." || dir == ".." ? string.Empty : dir);
        }
Ejemplo n.º 10
0
        private void List_OnNewLineEvent(object sender, NewLineEventArgs e)
        {
            string line = _client.UsedEncoding.GetString(e.Line.Content.Data, 0, e.Line.Content.Size);

            line = line.TrimEnd(crlfChars);

            FtpItem item = _client.FtpItemResolver.Resolve(line);

            _items.Add(item);
            OnNewFtpItem(item);
        }
Ejemplo n.º 11
0
 private void openURLToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (lvFTPList.SelectedItems.Count > 0)
     {
         FtpItem file = lvFTPList.SelectedItems[0].Tag as FtpItem;
         if (file != null && file.ItemType == FtpItemType.File)
         {
             ThreadPool.QueueUserWorkItem(x => Process.Start(Account.GetUriPath("@" + file.FullPath)));
         }
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="unFtpItem"></param>
 /// <param name="cheminCompletFichierSurServeur"></param>
 public ElementFolder(FtpItem unFtpItem, string cheminCompletFichierSurServeur)
 {
     if (unFtpItem.IsFolder)
     {
         _path        = cheminCompletFichierSurServeur;
         Name         = unFtpItem.Name;
         _mesElements = new List <ITransfer>();
     }
     else
     {
     }
 }
Ejemplo n.º 13
0
 private void lvFTPList_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e)
 {
     if (lvFTPList.SelectedItems.Count > 0 && !e.Cancel && !string.IsNullOrEmpty(e.DisplayText))
     {
         FtpItem file = (FtpItem)lvFTPList.SelectedItems[0].Tag;
         if (file.Name != e.DisplayText)
         {
             FTPAdapter.Rename(file.FullPath, Helpers.CombineURL(currentDirectory, e.DisplayText));
             RefreshDirectory();
         }
     }
 }
        private void UpdateFtpDetails()
        {
            int     ftpId   = Get.GetFtpItemId(DropDownListFTPSites.SelectedItem.Text);
            FtpItem ftpItem = Get.GetFtpItem(ftpId);

            if (ftpItem != null)
            {
                TextBoxFtpName.Text     = ftpItem.FtpName;
                TextBoxFtpAddress.Text  = ftpItem.FtpAddress;
                TextBoxFtpUserName.Text = ftpItem.FtpUsername;
                TextBoxFtpPassword.Text = ftpItem.FtpPassword;
            }
        }
Ejemplo n.º 15
0
 public ElementFile(FtpItem unFtpItem, string cheminCompletFichierSurServeur)
 {
     if (unFtpItem.IsFolder)
     {
         _path = cheminCompletFichierSurServeur;
         Name  = unFtpItem.Name;
     }
     else
     {
         _path = cheminCompletFichierSurServeur;
         Name  = unFtpItem.Name;
     }
 }
Ejemplo n.º 16
0
        static bool TryParseVaxList(string buf, out FtpItem item)
        {
            string regex =
                @"(?<name>.+)\.(?<extension>.+);(?<version>\d+)\s+" +
                @"(?<size>\d+)\s+" +
                @"(?<modify>\d+-\w+-\d+\s+\d+:\d+)";
            Match m;

            item = new FtpItem();

            if ((m = Regex.Match(buf, regex)).Success)
            {
                item.FullName = string.Format("{0}.{1};{2}",
                                              m.Groups["name"].Value,
                                              m.Groups["extension"].Value,
                                              m.Groups["version"].Value);

                if (m.Groups["extension"].Value.ToUpper() == "DIR")
                {
                    item.Type = FtpFileSystemObjectType.Directory;
                }
                else
                {
                    item.Type = FtpFileSystemObjectType.File;
                }

                long size;
                if (!long.TryParse(m.Groups["size"].Value, out size))
                {
                    item.Size = -1;
                }
                else
                {
                    item.Size = size;
                }

                DateTime date;
                if (!DateTime.TryParse(m.Groups["modify"].Value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out date))
                {
                    item.Modified = DateTime.MinValue;
                }
                else
                {
                    item.Modified = date;
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 17
0
        /// <summary> 
        /// Parses IIS DOS format listings 
        /// </summary> 
        /// <param name="buf">A line from the listing</param> 
        /// <param name="item"></param> 
        /// <returns>if the item is able to be parsed</returns> 
        private static bool TryParseDosList(string buf, out FtpItem item)
        {
            item = new FtpItem();
            string[] datefmt = new string[]
            {
                "MM-dd-yy  hh:mmtt",
                "MM-dd-yyyy  hh:mmtt"
            };
            Match m;

            // directory
            if (
                (m =
                    Regex.Match(buf, @"(?<modify>\d+-\d+-\d+\s+\d+:\d+\w+)\s+<DIR>\s+(?<name>.*)$",
                        RegexOptions.IgnoreCase)).Success)
            {
                DateTime modify;

                item.Type = FtpFileSystemObjectType.Directory;
                item.Name = m.Groups["name"].Value;

                //if (DateTime.TryParse(m.Groups["modify"].Value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out modify))
                if (DateTime.TryParseExact(m.Groups["modify"].Value, datefmt, CultureInfo.InvariantCulture,
                    DateTimeStyles.AssumeUniversal, out modify))
                    item.Modified = modify;
            }
            // file
            else if (
                (m =
                    Regex.Match(buf, @"(?<modify>\d+-\d+-\d+\s+\d+:\d+\w+)\s+(?<size>\d+)\s+(?<name>.*)$",
                        RegexOptions.IgnoreCase)).Success)
            {
                DateTime modify;
                long size;

                item.Type = FtpFileSystemObjectType.File;
                item.Name = m.Groups["name"].Value;

                if (long.TryParse(m.Groups["size"].Value, out size))
                    item.Size = size;

                //if (DateTime.TryParse(m.Groups["modify"].Value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out modify))
                if (DateTime.TryParseExact(m.Groups["modify"].Value, datefmt, CultureInfo.InvariantCulture,
                    DateTimeStyles.AssumeUniversal, out modify))
                    item.Modified = modify;
            }
            else
                return false;

            return true;
        }
Ejemplo n.º 18
0
 private void FTPRename()
 {
     if (lvFTPList.SelectedItems.Count > 0)
     {
         FtpItem file = lvFTPList.SelectedItems[0].Tag as FtpItem;
         if (file != null && file.ItemType != FtpItemType.Unknown)
         {
             lvFTPList.StartEditing(txtRename, lvFTPList.SelectedItems[0], 0);
             int offset = 23;
             txtRename.Left  += offset;
             txtRename.Width -= offset;
         }
     }
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Parses IIS DOS format listings
        /// </summary>
        /// <param name="buf">A line from the listing</param>
        /// <param name="item"></param>
        /// <returns>if the item is able to be parsed</returns>
        static bool TryParseDosList(string buf, out FtpItem item)
        {
            item = new FtpItem();
            string[] datefmt = new string[] {
                "MM-dd-yy  hh:mmtt",
                "MM-dd-yyyy  hh:mmtt"
            };
            Match m;

            // directory
            if ((m = Regex.Match(buf, @"(?<modify>\d+-\d+-\d+\s+\d+:\d+\w+)\s+<DIR>\s+(?<name>.*)$", RegexOptions.IgnoreCase)).Success)
            {
                DateTime modify;

                item.Type = FtpFileSystemObjectType.Directory;
                item.Name = m.Groups["name"].Value;

                //if (DateTime.TryParse(m.Groups["modify"].Value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out modify))
                if (DateTime.TryParseExact(m.Groups["modify"].Value, datefmt, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out modify))
                {
                    item.Modified = modify;
                }
            }
            // file
            else if ((m = Regex.Match(buf, @"(?<modify>\d+-\d+-\d+\s+\d+:\d+\w+)\s+(?<size>\d+)\s+(?<name>.*)$", RegexOptions.IgnoreCase)).Success)
            {
                DateTime modify;
                long     size;

                item.Type = FtpFileSystemObjectType.File;
                item.Name = m.Groups["name"].Value;

                if (long.TryParse(m.Groups["size"].Value, out size))
                {
                    item.Size = size;
                }

                //if (DateTime.TryParse(m.Groups["modify"].Value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out modify))
                if (DateTime.TryParseExact(m.Groups["modify"].Value, datefmt, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out modify))
                {
                    item.Modified = modify;
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 20
0
 public static NetworkItemInfo ToNetworkItemInfo(this FtpItem item, Uri uri, TappedEventHandler tapped, RightTappedEventHandler rightTapped, HoldingEventHandler holding, bool isOrderByName)
 {
     return(new NetworkItemInfo()
     {
         ServerType = ServerTypes.FTP,
         Created = item.Created,
         IsFile = item.Type == FtpFileSystemObjectType.File,
         Modified = item.Modified,
         Name = item.Name,
         Size = item.Size,
         Uri = new Uri(uri, item.FullName),
         Tapped = tapped,
         RightTapped = rightTapped,
         Holding = holding,
         IsOrderByName = isOrderByName,
     });
 }
Ejemplo n.º 21
0
        internal FtpItem[] Execute(int timeout, string dir)
        {
            FtpItem[] items = null;
            SetProgress(true);
            try
            {
                CreateDTP();
                _linesBuilder.NewLineEvent += new LinesBuilder.NewLineEventHandler(List_OnNewLineEvent);
                _items.Clear();
                _linesBuilder.Reset();

                string cmd = "LIST";
                if (null != dir)
                {
                    cmd += " " + dir;
                }

                _currentDTP.DataTransfered += new Cmd_RunDTP.DataTransferedEventHandler(List_OnDataTransfered);
                try
                {
                    _currentDTP.Execute(timeout,
                                        cmd,
                                        FtpDataType.Ascii,
                                        -1,
                                        new DTPStreamCommon(Stream.Null, DTPStreamType.ForWriting));
                }
                finally
                {
                    _currentDTP.DataTransfered -= new Cmd_RunDTP.DataTransferedEventHandler(List_OnDataTransfered);
                }

                items = new FtpItem[_items.Count];
                _items.CopyTo(items);
            }
            finally
            {
                if (null != _currentDTP)
                {
                    _currentDTP.Dispose();
                    _currentDTP = null;
                }
                _linesBuilder.NewLineEvent -= new LinesBuilder.NewLineEventHandler(List_OnNewLineEvent);
                SetProgress(false);
            }
            return(items);
        }
Ejemplo n.º 22
0
        private void lvFTPList_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool enabled = false;

            if (lvFTPList.SelectedItems.Count > 0)
            {
                FtpItem file = lvFTPList.SelectedItems[0].Tag as FtpItem;

                if (file != null)
                {
                    enabled = file.ItemType != FtpItemType.Unknown;
                }
            }

            downloadToolStripMenuItem.Enabled = renameToolStripMenuItem.Enabled = deleteToolStripMenuItem.Enabled =
                copyURLsToClipboardToolStripMenuItem.Enabled = openURLToolStripMenuItem.Enabled = enabled;

            CheckFiles(lvFTPList.SelectedItems.Count > 0);
        }
Ejemplo n.º 23
0
        private void lvFTPList_ItemDrag(object sender, ItemDragEventArgs e)
        {
            if (lvFTPList.SelectedItems.Count > 0)
            {
                List <string> filenames = new List <string>();
                foreach (ListViewItem lvi in lvFTPList.SelectedItems)
                {
                    FtpItem file = lvi.Tag as FtpItem;
                    if (file != null && !string.IsNullOrEmpty(file.Name))
                    {
                        filenames.Add(file.Name);
                    }
                }

                if (filenames.Count > 0)
                {
                    lvFTPList.DoDragDrop(filenames.ToArray(), DragDropEffects.Move);
                }
            }
        }
Ejemplo n.º 24
0
        private void FTPDownload(bool openDirectory)
        {
            if (lvFTPList.SelectedItems.Count > 0)
            {
                FtpItem checkDirectory = lvFTPList.SelectedItems[0].Tag as FtpItem;

                if (openDirectory && checkDirectory != null)
                {
                    if (checkDirectory.ItemType == FtpItemType.Unknown && checkDirectory.Name == "..")
                    {
                        FTPNavigateBack();
                        return;
                    }

                    if (checkDirectory.ItemType == FtpItemType.Directory)
                    {
                        LoadDirectory(checkDirectory.FullPath);
                        return;
                    }
                }

                FolderBrowserDialog fbd = new FolderBrowserDialog();
                fbd.RootFolder = Environment.SpecialFolder.Desktop;

                if (fbd.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(fbd.SelectedPath))
                {
                    FtpItemCollection list = new FtpItemCollection();
                    foreach (ListViewItem lvi in lvFTPList.SelectedItems)
                    {
                        FtpItem file = lvi.Tag as FtpItem;
                        if (file != null)
                        {
                            list.Add(file);
                        }
                    }

                    FTPAdapter.DownloadFiles(list, fbd.SelectedPath);
                }
            }
        }
Ejemplo n.º 25
0
        private void copyURLsToClipboardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string        path;
            List <string> list = new List <string>();

            foreach (ListViewItem lvi in lvFTPList.SelectedItems)
            {
                FtpItem file = lvi.Tag as FtpItem;
                if (file != null && file.ItemType == FtpItemType.File)
                {
                    path = Helpers.CombineURL(Account.HttpHomePath, file.FullPath);
                    list.Add(path);
                }
            }

            string clipboard = string.Join("\r\n", list.ToArray());

            if (!string.IsNullOrEmpty(clipboard))
            {
                ClipboardHelpers.CopyText(clipboard);
            }
        }
Ejemplo n.º 26
0
 public void TestGetFileInfo(string host, int port, FtpSecurityProtocol protocol,
                             string user, string pwd, ListingMethod method)
 {
     using (FtpClient c = new FtpClient(host, port, protocol))
     {
         Debug.WriteLine("********** BEGINNING **********");
         c.AlwaysAcceptServerCertificate = true;
         c.DirListingMethod = method;
         c.Open(user, pwd);
         Assert.IsTrue(c.IsConnected);
         // get information about the root directory
         FtpItem m = c.GetFileInfo(".");
         if (m is FtpMlsxItem)
         {
             Debug.Write(((FtpMlsxItem)m).ToString());
         }
         else
         {
             Debug.Write(m.ToString());
         }
         Debug.WriteLine("********** ENDING **********");
     }
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Parses MLS* format listings
        /// </summary>
        /// <param name="buf">A line from the listing</param>
        /// <param name="item"></param>
        /// <returns>if the item is able to be parsed</returns>
        static bool TryParseMachineList(string buf, out FtpItem item)
        {
            item = new FtpItem();
            Match m;

            if (!(m = Regex.Match(buf, "type=(?<type>.+?);", RegexOptions.IgnoreCase)).Success)
            {
                return(false);
            }

            switch (m.Groups["type"].Value.ToLower())
            {
            case "dir":
                item.Type = FtpFileSystemObjectType.Directory;
                break;

            case "file":
                item.Type = FtpFileSystemObjectType.File;
                break;

            // These are not supported for now.
            case "link":
            case "device":
            default:
                return(false);
            }

            if ((m = Regex.Match(buf, "; (?<name>.*)$", RegexOptions.IgnoreCase)).Success)
            {
                item.Name = m.Groups["name"].Value;
            }
            else // if we can't parse the file name there is a problem.
            {
                return(false);
            }

            if ((m = Regex.Match(buf, "modify=(?<modify>.+?);", RegexOptions.IgnoreCase)).Success)
            {
                item.Modified = m.Groups["modify"].Value.GetFtpDate(DateTimeStyles.AssumeUniversal);
            }

            if ((m = Regex.Match(buf, "created?=(?<create>.+?);", RegexOptions.IgnoreCase)).Success)
            {
                item.Created = m.Groups["create"].Value.GetFtpDate(DateTimeStyles.AssumeUniversal);
            }

            if ((m = Regex.Match(buf, @"size=(?<size>\d+);", RegexOptions.IgnoreCase)).Success)
            {
                long size;

                if (long.TryParse(m.Groups["size"].Value, out size))
                {
                    item.Size = size;
                }
            }

            if ((m = Regex.Match(buf, @"unix.mode=(?<mode>\d+);", RegexOptions.IgnoreCase)).Success)
            {
                if (m.Groups["mode"].Value.Length == 4)
                {
                    item.SpecialPermissions = (FtpSpecialPermissions)int.Parse(m.Groups["mode"].Value[0].ToString());
                    item.OwnerPermissions   = (FtpPermission)int.Parse(m.Groups["mode"].Value[1].ToString());
                    item.GroupPermissions   = (FtpPermission)int.Parse(m.Groups["mode"].Value[2].ToString());
                    item.OthersPermissions  = (FtpPermission)int.Parse(m.Groups["mode"].Value[3].ToString());
                }
                else if (m.Groups["mode"].Value.Length == 3)
                {
                    item.OwnerPermissions  = (FtpPermission)int.Parse(m.Groups["mode"].Value[0].ToString());
                    item.GroupPermissions  = (FtpPermission)int.Parse(m.Groups["mode"].Value[1].ToString());
                    item.OthersPermissions = (FtpPermission)int.Parse(m.Groups["mode"].Value[2].ToString());
                }
            }

            return(true);
        }
Ejemplo n.º 28
0
 public static NetworkItemInfo ToNetworkItemInfo(this FtpItem item, Uri uri)
 {
     return(ToNetworkItemInfo(item, uri, null, null, null, false));
 }
Ejemplo n.º 29
0
        private static bool TryParseVaxList(string buf, out FtpItem item)
        {
            string regex =
                @"(?<name>.+)\.(?<extension>.+);(?<version>\d+)\s+" +
                @"(?<size>\d+)\s+" +
                @"(?<modify>\d+-\w+-\d+\s+\d+:\d+)";
            Match m;

            item = new FtpItem();

            if ((m = Regex.Match(buf, regex)).Success)
            {

                item.FullName = string.Format("{0}.{1};{2}",
                    m.Groups["name"].Value,
                    m.Groups["extension"].Value,
                    m.Groups["version"].Value);

                if (m.Groups["extension"].Value.ToUpper() == "DIR")
                    item.Type = FtpFileSystemObjectType.Directory;
                else
                    item.Type = FtpFileSystemObjectType.File;

                long size;
                if (!long.TryParse(m.Groups["size"].Value, out size))
                    item.Size = -1;
                else
                    item.Size = size;

                DateTime date;
                if (
                    !DateTime.TryParse(m.Groups["modify"].Value, CultureInfo.InvariantCulture,
                        DateTimeStyles.AssumeLocal, out date))
                    item.Modified = DateTime.MinValue;
                else
                    item.Modified = date;

                return true;
            }

            return false;
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Parses LIST format listings
        /// </summary>
        /// <param name="buf">A line from the listing</param>
        /// <param name="capabilities">Server capabilities</param>
        /// <param name="item"></param>
        /// <returns>if the item is able to be parsed</returns>
        static bool TryParseUnixList(string buf, FtpCapability capabilities, out FtpItem item)
        {
            string regex =
                @"(?<permissions>[\w-]{10})\s+" +
                @"(?<objectcount>\d+)\s+" +
                @"(?<user>[\w\d]+)\s+" +
                @"(?<group>[\w\d]+)\s+" +
                @"(?<size>\d+)\s+" +
                @"(?<modify>\w+\s+\d+\s+\d+:\d+|\w+\s+\d+\s+\d+)\s+" +
                @"(?<name>.*)$";

            item = new FtpItem();
            Match m;

            if (!(m = Regex.Match(buf, regex, RegexOptions.IgnoreCase)).Success)
            {
                return(false);
            }

            if (m.Groups["permissions"].Value.StartsWith("d"))
            {
                item.Type = FtpFileSystemObjectType.Directory;
            }
            else if (m.Groups["permissions"].Value.StartsWith("-"))
            {
                item.Type = FtpFileSystemObjectType.File;
            }
            else
            {
                return(false);
            }

            // if we can't determine a file name then
            // we are not considering this a successful parsing operation.
            if (m.Groups["name"].Value.Length < 1)
            {
                return(false);
            }
            item.Name = m.Groups["name"].Value;

            if (item.Type == FtpFileSystemObjectType.Directory && (item.Name == "." || item.Name == ".."))
            {
                return(false);
            }

            ////
            // Ignore the Modify times sent in LIST format for files
            // when the server has support for the MDTM command
            // because they will never be as accurate as what can be had
            // by using the MDTM command. MDTM does not work on directories
            // so if a modify time was parsed from the listing we will try
            // to convert it to a DateTime object and use it for directories.
            ////
            if ((!capabilities.HasFlag(FtpCapability.MDTM) || item.Type == FtpFileSystemObjectType.Directory) && m.Groups["modify"].Value.Length > 0)
            {
                item.Modified = m.Groups["modify"].Value.GetFtpDate(DateTimeStyles.AssumeLocal);
            }

            if (m.Groups["size"].Value.Length > 0)
            {
                long size;

                if (long.TryParse(m.Groups["size"].Value, out size))
                {
                    item.Size = size;
                }
            }

            if (m.Groups["permissions"].Value.Length > 0)
            {
                Match perms = Regex.Match(m.Groups["permissions"].Value,
                                          @"[\w-]{1}(?<owner>[\w-]{3})(?<group>[\w-]{3})(?<others>[\w-]{3})",
                                          RegexOptions.IgnoreCase);

                if (perms.Success)
                {
                    if (perms.Groups["owner"].Value.Length == 3)
                    {
                        if (perms.Groups["owner"].Value[0] == 'r')
                        {
                            item.OwnerPermissions |= FtpPermission.Read;
                        }
                        if (perms.Groups["owner"].Value[1] == 'w')
                        {
                            item.OwnerPermissions |= FtpPermission.Write;
                        }
                        if (perms.Groups["owner"].Value[2] == 'x' || perms.Groups["owner"].Value[2] == 's')
                        {
                            item.OwnerPermissions |= FtpPermission.Execute;
                        }
                        if (perms.Groups["owner"].Value[2] == 's' || perms.Groups["owner"].Value[2] == 'S')
                        {
                            item.SpecialPermissions |= FtpSpecialPermissions.SetUserID;
                        }
                    }

                    if (perms.Groups["group"].Value.Length == 3)
                    {
                        if (perms.Groups["group"].Value[0] == 'r')
                        {
                            item.GroupPermissions |= FtpPermission.Read;
                        }
                        if (perms.Groups["group"].Value[1] == 'w')
                        {
                            item.GroupPermissions |= FtpPermission.Write;
                        }
                        if (perms.Groups["group"].Value[2] == 'x' || perms.Groups["group"].Value[2] == 's')
                        {
                            item.GroupPermissions |= FtpPermission.Execute;
                        }
                        if (perms.Groups["group"].Value[2] == 's' || perms.Groups["group"].Value[2] == 'S')
                        {
                            item.SpecialPermissions |= FtpSpecialPermissions.SetGroupID;
                        }
                    }

                    if (perms.Groups["others"].Value.Length == 3)
                    {
                        if (perms.Groups["others"].Value[0] == 'r')
                        {
                            item.OthersPermissions |= FtpPermission.Read;
                        }
                        if (perms.Groups["others"].Value[1] == 'w')
                        {
                            item.OthersPermissions |= FtpPermission.Write;
                        }
                        if (perms.Groups["others"].Value[2] == 'x' || perms.Groups["others"].Value[2] == 't')
                        {
                            item.OthersPermissions |= FtpPermission.Execute;
                        }
                        if (perms.Groups["others"].Value[2] == 't' || perms.Groups["others"].Value[2] == 'T')
                        {
                            item.SpecialPermissions |= FtpSpecialPermissions.Sticky;
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 31
0
        /// <summary> 
        /// Parses LIST format listings 
        /// </summary> 
        /// <param name="buf">A line from the listing</param> 
        /// <param name="capabilities">Server capabilities</param> 
        /// <param name="item"></param> 
        /// <returns>if the item is able to be parsed</returns> 
        private static bool TryParseUnixList(string buf, FtpCapability capabilities, out FtpItem item)
        {
            string regex =
                @"(?<permissions>[\w-]{10})\s+" +
                @"(?<objectcount>\d+)\s+" +
                @"(?<user>[\w\d]+)\s+" +
                @"(?<group>[\w\d]+)\s+" +
                @"(?<size>\d+)\s+" +
                @"(?<modify>\w+\s+\d+\s+\d+:\d+|\w+\s+\d+\s+\d+)\s+" +
                @"(?<name>.*)$";

            item = new FtpItem();
            Match m;

            if (!(m = Regex.Match(buf, regex, RegexOptions.IgnoreCase)).Success)
                return false;

            if (m.Groups["permissions"].Value.StartsWith("d"))
                item.Type = FtpFileSystemObjectType.Directory;
            else if (m.Groups["permissions"].Value.StartsWith("-"))
                item.Type = FtpFileSystemObjectType.File;
            else
                return false;

            // if we can't determine a file name then
            // we are not considering this a successful parsing operation.
            if (m.Groups["name"].Value.Length < 1)
                return false;
            item.Name = m.Groups["name"].Value;

            if (item.Type == FtpFileSystemObjectType.Directory && (item.Name == "." || item.Name == ".."))
                return false;

            ////
            // Ignore the Modify times sent in LIST format for files
            // when the server has support for the MDTM command
            // because they will never be as accurate as what can be had
            // by using the MDTM command. MDTM does not work on directories
            // so if a modify time was parsed from the listing we will try
            // to convert it to a DateTime object and use it for directories.
            ////
            if ((!capabilities.HasFlag(FtpCapability.MDTM) || item.Type == FtpFileSystemObjectType.Directory) &&
                m.Groups["modify"].Value.Length > 0)
                item.Modified = m.Groups["modify"].Value.GetFtpDate(DateTimeStyles.AssumeLocal);

            if (m.Groups["size"].Value.Length > 0)
            {
                long size;

                if (long.TryParse(m.Groups["size"].Value, out size))
                    item.Size = size;
            }

            if (m.Groups["permissions"].Value.Length > 0)
            {
                Match perms = Regex.Match(m.Groups["permissions"].Value,
                    @"[\w-]{1}(?<owner>[\w-]{3})(?<group>[\w-]{3})(?<others>[\w-]{3})",
                    RegexOptions.IgnoreCase);

                if (perms.Success)
                {
                    if (perms.Groups["owner"].Value.Length == 3)
                    {
                        if (perms.Groups["owner"].Value[0] == 'r')
                            item.OwnerPermissions |= FtpPermission.Read;
                        if (perms.Groups["owner"].Value[1] == 'w')
                            item.OwnerPermissions |= FtpPermission.Write;
                        if (perms.Groups["owner"].Value[2] == 'x' || perms.Groups["owner"].Value[2] == 's')
                            item.OwnerPermissions |= FtpPermission.Execute;
                        if (perms.Groups["owner"].Value[2] == 's' || perms.Groups["owner"].Value[2] == 'S')
                            item.SpecialPermissions |= FtpSpecialPermissions.SetUserID;
                    }

                    if (perms.Groups["group"].Value.Length == 3)
                    {
                        if (perms.Groups["group"].Value[0] == 'r')
                            item.GroupPermissions |= FtpPermission.Read;
                        if (perms.Groups["group"].Value[1] == 'w')
                            item.GroupPermissions |= FtpPermission.Write;
                        if (perms.Groups["group"].Value[2] == 'x' || perms.Groups["group"].Value[2] == 's')
                            item.GroupPermissions |= FtpPermission.Execute;
                        if (perms.Groups["group"].Value[2] == 's' || perms.Groups["group"].Value[2] == 'S')
                            item.SpecialPermissions |= FtpSpecialPermissions.SetGroupID;
                    }

                    if (perms.Groups["others"].Value.Length == 3)
                    {
                        if (perms.Groups["others"].Value[0] == 'r')
                            item.OthersPermissions |= FtpPermission.Read;
                        if (perms.Groups["others"].Value[1] == 'w')
                            item.OthersPermissions |= FtpPermission.Write;
                        if (perms.Groups["others"].Value[2] == 'x' || perms.Groups["others"].Value[2] == 't')
                            item.OthersPermissions |= FtpPermission.Execute;
                        if (perms.Groups["others"].Value[2] == 't' || perms.Groups["others"].Value[2] == 'T')
                            item.SpecialPermissions |= FtpSpecialPermissions.Sticky;
                    }
                }
            }

            return true;
        }
Ejemplo n.º 32
0
        private void lvFTPList_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(string[])))
            {
                Point        point = lvFTPList.PointToClient(new Point(e.X, e.Y));
                ListViewItem lvi   = lvFTPList.GetItemAt(point.X, point.Y);
                if (lvi != null && e.AllowedEffect == DragDropEffects.Move)
                {
                    if (tempSelected != null && tempSelected != lvi)
                    {
                        tempSelected.Selected = false;
                    }

                    FtpItem file = lvi.Tag as FtpItem;
                    if (file != null && file.ItemType == FtpItemType.Directory)
                    {
                        string[] filenames = e.Data.GetData(typeof(string[])) as string[];
                        if (filenames != null)
                        {
                            int renameCount = 0;
                            foreach (string filename in filenames)
                            {
                                if (file.Name != filename)
                                {
                                    string path     = Helpers.CombineURL(currentDirectory, filename);
                                    string movePath = string.Empty;
                                    if (file.ItemType == FtpItemType.Unknown)
                                    {
                                        if (file.Name == ".")
                                        {
                                            movePath = FTPHelpers.AddSlash(filename, FTPHelpers.SlashType.Prefix, 2);
                                        }
                                        else if (file.Name == "..")
                                        {
                                            movePath = FTPHelpers.AddSlash(filename, FTPHelpers.SlashType.Prefix);
                                        }
                                    }
                                    else
                                    {
                                        movePath = Helpers.CombineURL(file.FullPath, filename);
                                    }

                                    if (!string.IsNullOrEmpty(movePath))
                                    {
                                        FTPAdapter.Rename(path, movePath);
                                        renameCount++;
                                    }
                                }
                            }

                            if (renameCount > 0)
                            {
                                RefreshDirectory();
                            }
                        }
                    }
                }

                tempSelected = null;
            }
            else if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
                if (files != null)
                {
                    FTPAdapter.UploadFiles(files, currentDirectory);
                    RefreshDirectory();
                }
            }
        }
Ejemplo n.º 33
0
 public FtpFolderBasicProperties(FtpItem item)
 {
     DateModified = item.ItemDateModifiedReal;
     ItemDate     = item.ItemDateCreatedReal;
     Size         = (ulong)item.FileSizeBytes;
 }
Ejemplo n.º 34
0
        /// <summary> 
        /// Parses MLS* format listings 
        /// </summary> 
        /// <param name="buf">A line from the listing</param> 
        /// <param name="item"></param> 
        /// <returns>if the item is able to be parsed</returns> 
        private static bool TryParseMachineList(string buf, out FtpItem item)
        {
            item = new FtpItem();
            Match m;

            if (!(m = Regex.Match(buf, "type=(?<type>.+?);", RegexOptions.IgnoreCase)).Success)
                return false;

            switch (m.Groups["type"].Value.ToLower())
            {
                case "dir":
                    item.Type = FtpFileSystemObjectType.Directory;
                    break;
                case "file":
                    item.Type = FtpFileSystemObjectType.File;
                    break;
                // These are not supported for now.
                case "link":
                case "device":
                default:
                    return false;
            }

            if ((m = Regex.Match(buf, "; (?<name>.*)$", RegexOptions.IgnoreCase)).Success)
                item.Name = m.Groups["name"].Value;
            else // if we can't parse the file name there is a problem.
                return false;

            if ((m = Regex.Match(buf, "modify=(?<modify>.+?);", RegexOptions.IgnoreCase)).Success)
                item.Modified = m.Groups["modify"].Value.GetFtpDate(DateTimeStyles.AssumeUniversal);

            if ((m = Regex.Match(buf, "created?=(?<create>.+?);", RegexOptions.IgnoreCase)).Success)
                item.Created = m.Groups["create"].Value.GetFtpDate(DateTimeStyles.AssumeUniversal);

            if ((m = Regex.Match(buf, @"size=(?<size>\d+);", RegexOptions.IgnoreCase)).Success)
            {
                long size;

                if (long.TryParse(m.Groups["size"].Value, out size))
                    item.Size = size;
            }

            if ((m = Regex.Match(buf, @"unix.mode=(?<mode>\d+);", RegexOptions.IgnoreCase)).Success)
            {
                if (m.Groups["mode"].Value.Length == 4)
                {
                    item.SpecialPermissions = (FtpSpecialPermissions) int.Parse(m.Groups["mode"].Value[0].ToString());
                    item.OwnerPermissions = (FtpPermission) int.Parse(m.Groups["mode"].Value[1].ToString());
                    item.GroupPermissions = (FtpPermission) int.Parse(m.Groups["mode"].Value[2].ToString());
                    item.OthersPermissions = (FtpPermission) int.Parse(m.Groups["mode"].Value[3].ToString());
                }
                else if (m.Groups["mode"].Value.Length == 3)
                {
                    item.OwnerPermissions = (FtpPermission) int.Parse(m.Groups["mode"].Value[0].ToString());
                    item.GroupPermissions = (FtpPermission) int.Parse(m.Groups["mode"].Value[1].ToString());
                    item.OthersPermissions = (FtpPermission) int.Parse(m.Groups["mode"].Value[2].ToString());
                }
            }

            return true;
        }