Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ftp listfiles returns wrong array from Microsoft FTP Service

99 views
Skip to first unread message

FabioNery

unread,
May 9, 2013, 8:42:09 AM5/9/13
to
Hi,

The ftp:listfiles returns wrong array from Microsoft FTP Service.

Example Microsoft FTP: Date Time <dir>/size name

dd-mm-aa hh:mmAM <DIR> meudir1
dd-mm-aa hh:mmAM <DIR> meudir2
dd-mm-aa hh:mmAM 1234 meufile

Default listfiles in FTPCLN.PRG: permissions owner group filesize date
filename

lrw-r--r-- ftp ftp D 28 2009-06-17 debian
lrw-r--r-- ftp ftp D 31 2009-06-17 debian-cd
-rw-r--r-- ftp ftp 0 2010-03-04 13:30 keepalive.txt
drwxr-xr-x ftp ftp D 4096 2010-02-18 14:22 mirror
lrw-r--r-- ftp ftp D 6 2009-06-17 mirrors
drwxr-xr-x ftp ftp D 4096 2009-06-23 packages
lrw-r--r-- ftp ftp D 1 2009-06-17 pub
What better way to treat this problem? Has anyone got any patches you can
share?

TIA,
FabioNery


FabioNery

unread,
May 9, 2013, 8:47:42 AM5/9/13
to
Hi,

In
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/7758e7a8-e063-4eec-a6c1-c76a59d02852/
has a solution in C#. How implement in xharbour?

How to identify if the ftp is microsoft or not and apply the algorithm
existing or specifically for microsoft?

TIA,
FabioNery




"FabioNery" <des...@s2info.com.br> escreveu na mensagem
news:kmg5bu$ub1$1...@dont-email.me...

cul...@gmail.com

unread,
May 9, 2013, 10:32:14 AM5/9/13
to
Fabio

xharbour one return the correct, since it need to bring all this data.

Regards
Luiz

FabioNery

unread,
May 9, 2013, 11:15:15 AM5/9/13
to
Hi Luiz,

In this code:

[CODE]
...
aArqsFtp := oFtp:listFiles( '*.txt' )
FOR EACH aFile IN aArqsFtp
alert( aFile[F_ATTR] ) // in linux ftp returns '-lrsrs' in ms
ftp returns '05-08-13'
alert( aFile[F_NAME] ) // in linux ftp returns 'arq.txt' in ms
ftp returns '05-08-13 05:32PM 760 arq.txt'
IF aFile[F_ATTR][1] <> "-" // '-' = Regular file // IN MS FTP
don't works
LOOP
ENDIF
NEXT
[/CODE]

alert( aFile[F_ATTR] ) results:

linux ftp = '-rsrs' // correct
ms ftp = '05-08-13' // wrong

alert( aFile[F_NAME] ) results:

linux ftp = 'arq.txt' // correct
ms ftp = '05-08-13 05:32PM 760 arq.txt' // wrong

The parser in METHOD listFiles( cFileSpec ) don�t work well in microsoft ftp
service.

TIA,
FabioNery


<cul...@gmail.com> escreveu na mensagem
news:cf1532db-a231-4636...@googlegroups.com...

FabioNery

unread,
May 9, 2013, 6:26:51 PM5/9/13
to
Hi,

Date format correct is mm-dd-aa

Example Microsoft FTP: Date Time <dir>/size name

mm-dd-aa hh:mmAM <DIR> meudir1


FabioNery

"FabioNery" <des...@s2info.com.br> escreveu na mensagem
news:kmg5bu$ub1$1...@dont-email.me...

FabioNery

unread,
May 9, 2013, 6:39:27 PM5/9/13
to
This function is working for download from microsoft ftp:

[code]

****************************************
STATIC FUNCTION F_FtpListFilesMicrosoft( cFileSpec )
****************************************

LOCAL Self := HB_QSelf(),;
cOldFormato,;
cList,;
aList,;
cEntry,;
nStart,;
nEnd,;
cTime,;
aFile

cList := ::list( cFileSpec )

IF Empty( cList )
RETURN {}
ENDIF

aList := hb_ATokens( StrTran( cList, Chr(13 ),'' ), Chr( 10 ) )

// Windows FTP Server Response Format
// DateCreated IsDirectory Name

FOR EACH cEntry IN aList

IF Empty( cEntry ) //PM:09-08-2007 Needed because of the new
HB_aTokens()

ADel( aList, HB_EnumIndex(), .T. )

ELSE

aFile := Array( F_LEN + 3 )
nStart := 1
nEnd := At( Chr( 32 ), cEntry, nStart )

// file date
aFile[F_DATE] := SubStr( cEntry, nStart, nEnd - nStart ) //
mm-dd-yy
cOldFormato := SET( _SET_DATEFORMAT )
SET( _SET_DATEFORMAT, 'MM-DD-YY' )
aFile[F_DATE] := CTOD( aFile[F_DATE] )
SET( _SET_DATEFORMAT, cOldFormato )
nStart := nEnd

// file time
DO WHILE cEntry[++nStart] == " " ; ENDDO
nEnd := At( Chr( 32 ), cEntry, nStart )
aFile[F_TIME] := UPPER( SubStr( cEntry, nStart, nEnd - nStart ) )
IF RIGHT( aFile[F_TIME], 2 ) = 'AM'
cTime := LEFT( aFile[F_TIME], 2 )
IF cTime = '12'
cTime := '00'
ENDIF
ELSE // PM
cTime := VAL( LEFT( aFile[F_TIME], 2 ) )
IF cTime <> 12
cTime += 12
ENDIF
cTime := STRZERO( cTime, 2 )
ENDIF
cTime += SUBS( aFile[F_TIME], 3, 3 ) + ':00'
aFile[F_TIME] := cTime // formato hh:mm:ss
nStart := nEnd

// proximos parses: file permissions (attributes) e filesize

DO WHILE cEntry[++nStart] == " " ; ENDDO
nEnd := At( Chr( 32 ), cEntry, nStart )

aFile[F_SIZE] := UPPER( SubStr( cEntry, nStart, nEnd - nStart ) )

IF '<DIR>' IN aFile[F_SIZE]
aFile[F_ATTR] := 'd' // � diret�rio
aFile[F_SIZE] := 0
ELSE
aFile[F_ATTR] := '-' // regular file
aFile[F_SIZE] := VAL( aFile[F_SIZE] )
ENDIF

nStart := nEnd

// file name
DO WHILE cEntry[++nStart] == " " ; ENDDO
aFile[F_NAME] := SubStr( cEntry, nStart )

// # of links
aFile[F_LEN+1] := 0

// owner name
aFile[F_LEN+2] := ''

// group name
aFile[F_LEN+3] := ''

aList[ HB_EnumIndex() ] := aFile

ENDIF

NEXT

RETURN aList

[/code]

TIA,
Fabio Nery




"FabioNery" <des...@s2info.com.br> escreveu na mensagem
news:kmh7kd$bhd$1...@dont-email.me...

Klas Engwall

unread,
May 10, 2013, 7:09:05 AM5/10/13
to
Hi Fabio,

The FTP standard does not specify what a file list should look like, so
different FTP server implementations have different solutions. Most, but
certainly not all, follow the UNIX "ls" format, but it kind of "makes
sense" :-) that Microsoft has their own approach also in this matter.

What Luiz says about xHarbour parsing the list correctly is nonsense.
The tIPClientFtp parser is definitely too simple, as you have noticed,
and can only handle the most straightforward ls format. I rewrote the
parser (locally only, not posted anywhere) to handle yet another list
format together with the UNIX ls format, but it does not handle the
Microsoft format. What tIP really needs is a little artificial
intelligence to try different solutions for each line if the result of
the first attempt to parse the line does not give the expected result.
In addition to what you found, there are for example FTP servers that
output directory entries in a totally different format (blank line plus
directory name plus colon and then nothing else).

Did you try FileZilla on the problem server? If they get it correctly,
maybe it is worth investigating how they do the parsing.

And another thing: You (or the original tIP parser) cannot safely use
Adel() to remove empty lines if you read the aList array from top to
bottom. It will skip the next entry after the empty line and leave it
unparsed! Instead, read the array from bottom to top. That will prevent
messing up the rest of aList.

Regards,
Klas
--


--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

FabioNery

unread,
May 10, 2013, 9:30:06 AM5/10/13
to
Hi Klas,

The Filezilla lists only name, date, time and size. No permissions.

I kept adel() in the example because it is in the original function. But I
modified the function in my prg.

Thank You,
Fabio Nery


"Klas Engwall" <klas.e...@nospam.please> escreveu na mensagem
news:kmik8m$2foj$1...@adenine.netfront.net...
0 new messages