Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FtpWebRequest cannot handle file with more than one spac
Message
De
28/11/2013 07:02:32
 
 
À
27/11/2013 17:42:14
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01588791
Message ID:
01588827
Vues:
44
This message has been marked as a message which has helped to the initial question of the thread.
>This is resolved. The problem was in the parsing of the directory that I need to collect a file to be downloaded. Initially, we decided to split the FTP directory listing by using the double space as a delimiter. But, this conflicts if I have a file name with double spaces. So, I had to adjust that to be a little bit longer but safer.

Update - I see the spaces in the filenames were addressed here message#1543391 - EndUpdate


I suppose this is related to thread#1588792

I don't really see a problem if there are consecutive spaces in the filename since we know that the filename is the last part(s) of the line

(1)
If you parse with string.Split http://msdn.microsoft.com/en-us/library/ms131448.aspx do not use StringSplitOptions.RemoveEmptyEntries
string s = "1  2 3   4";
string[] elements = s.Split(new char[] { ' ' }, StringSplitOptions.None);
When you traverse the result, each empty string in the array represents an extra space char in the original string
The parsing is a bit more difficult

(2) if you parse with Regex, since the filename is in the last parts you can take advantage of the $ anchor

(message#1543374) changed as follows

- the last line - lots of spaces in the file name
- the pattern for the filename
was [\S]+)$
becomes .+)$

The filename of the last line is correctly parsed
		internal static void Go()
		{
			string[] lines =
			{	@"drw-rw-rw-   1 user     group           0 Feb  6 15:46 .",
                @"drw-rw-rw-   1 user     group           0 Feb  6 15:46 ..",
                @"-rw-rw-rw-   1 user     group        4825 May  3  2010 Account.png",
                @"-rw-rw-rw-   1 user     group        5242 May  3  2010 Administration.png",
                @"-rw-rw-rw-   1 user     group        4117 Apr 17  2011 Agent.png",
                @"-rw-rw-rw-   1 user     group        1402 Dec 30  2005 AmazonCA.gif",
                @"-rw-rw-r--   1 wliclus  weblogic   308121 Jun  1  2011 tlv_01_jackk_2011615315_1185655_001_23327701.zip",
				@"-r-xr-xr-x   1 owner    group        78145990 Nov  4  2011 101.zip",
                @"-r-xr-xr-x   1 owner    group           35492 Apr 14  2011 20110414.40E",
                @"-r-xr-xr-x   1 owner    group           33583 Apr 14  2011 20110414.421",
                @"-r-xr-xr-x   1 owner    group           40815 Apr 14  2011 20110414.483",
                @"-r-xr-xr-x   1 owner    group           24836 Apr 14  2011 20110414.ARC",
                @"-r-xr-xr-x   1 owner    group            4737 May  5  2011 4A16PBE1.txt",
                @"-r-xr-xr-x   1 owner    group            4737 Jan 18 13:50 4A17A7B1 aa  bbb      cccccc.txt"
			};

			string pattern = @"^(?<Permissions>\S+)\s+(?<Links>\d+)\s+(?<User>\w+)\s+(?<Group>\w+)\s+(?<FileSize>\d+)\s+(?<Month>\w+)\s+(?<Day>\d+)\s+((?<Year>\d{4})|(?<Time>\d+:\d+(:\d+)?))\s+(?<FileName>.+)$";



			foreach (string line in lines)
			{
				Match m = Regex.Match(line, pattern);

				if (m.Success)
				{
					Console.WriteLine("Month {0}", m.Groups["Month"]);
					Console.WriteLine("Day {0}", m.Groups["Day"]);
					Console.WriteLine("Year {0}", m.Groups["Year"]);
					Console.WriteLine("Time {0}", m.Groups["Time"]);
					Console.WriteLine("Size {0}", m.Groups["FileSize"]);
					Console.WriteLine("FileName {0}", m.Groups["FileName"]);
				}
				else
					Console.WriteLine("No match");

			}


			Console.ReadLine();


		}
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform