LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Access FTP with whitespaces in dir names

Solved!
Go to solution

Hi, 

 

I'm trying to make a recursive list of files in an FTP directory.

 

While FileZilla deals with whitespaces in directory names with no problem, it seems that Labview struggles a bit.

 

Indeed, if I ask labview to get the files and directory of a folder named, for instance, /Projects/Camera 1/, it will return an empty array (while FileZilla clearly sees 12 files in this folder). It seems that the problem is the whitespace in the name because if I replace (using FileZilla) the space character with "_", LV correctly gives me the file list.

 

Any idea how to make the LabView FTP function correctly deal with whitespaces in directory and file names?

 

Best regards,

 

perper2001

0 Kudos
Message 1 of 13
(12,497 Views)

Try to replace the white space with %20

Message 2 of 13
(12,492 Views)

Thanks for your reply.

 

Unfortunately, replacing whitespaces with %20 doesn't work.

 

Regards,

 

peper2001

0 Kudos
Message 3 of 13
(12,487 Views)

The %20 syntax is HTTP escaping. It will only work in a web browser (with FTP support) which will convert the HTTP escaping to proper FTP syntax. Have you tried to enclose the entire file path in double quotes ("/Projects/Camera 1/")?

Rolf Kalbermatter
Averna BV
0 Kudos
Message 4 of 13
(12,478 Views)

Yep, i've tried enclosing the path with double quotes but it returns an empty file list.

 

What does work however is changing the current working directory (CWD) and then using the labview directory listing function with no file path. But it won't work with commands like /Projects/Camera 1/*.jpg.

 

What also work is using NLST instead of LIST (just modify a boolean in directory listing vi) but, with this function all files and directory are not correclty recognized and are detected as "link". 

 

What also work is using MLSD but the reply string is not compatible with the one that LIST returns and hence, the reply string is not correclty parsed.

 

I think my best option is to go with MLSD and rewrite the parsing algorithm... but if someone as a better option, I'm all hears!

 

Regards,

 

peper2001

0 Kudos
Message 5 of 13
(12,465 Views)

FYI, it works OK with the MLSD function.

0 Kudos
Message 6 of 13
(12,402 Views)

@peper2001 wrote:

FYI, it works OK with the MLSD function.


That is very possible. I haven't checked the FTP RFC in a while. Most likely they added those new commands to accomodate these new things explicitedly. Doesn't have to mean that an FTP server couldn't support quoted paths with the standard commands, but that is a feature of your FTP server, not of the client you use to talk to the server. So LabVIEW can't do anything about this here. It is mainly a feature that your FTP server has to provide and there might be differences between different FTP servers.

Rolf Kalbermatter
Averna BV
0 Kudos
Message 7 of 13
(12,390 Views)

OK, thanks for pointing that out.

 

Best regards,

 

peper2001

0 Kudos
Message 8 of 13
(12,379 Views)

peper2001,

     I'm running into the same issue. The LIST command works with many FTP servers, but fails on some servers to return files and directories if the directory name contains spaces. Of the various work-arounds you describe, the MSLD command sounds like the best approach, since the others have limitations. You mentioned that you got that to work. Is there any chance you could share some code? From what see, the MSLD command isn't even supported in the low-level FTP functions LabVIEW supplies. I don't imagine it would be too hard to figure out how to implement it, using the existing commands as a guide. But if you've done it already, that would be even easier!

     I put in a support request with NI when this happened. They pointed me toward your post. I'm going to suggest that they improve the FTP VI's that ship with LV to help address this. But it's not unlikely that the quickest solution will be if the community can provide one. If I am able to get MSLD (possibly with your help), I'll be glad to package it up into something that can be posted to the community.

Thanks,

     DaveT

-------------------------------------------------------------
David Thomson Original Code Consulting
www.originalcode.com
National Instruments Alliance Program Member
Certified LabVIEW Architect
Certified Embedded Systems Developer
-------------------------------------------------------------
There are 10 kinds of people: those who understand binary, and those who don't.
0 Kudos
Message 9 of 13
(12,143 Views)
Solution
Accepted by Dave_Thomson

Hi,

 

Unfortunately, I can't share the code but here is a screenshot of what it looks like.  It is based on the "directory listing vi" that is shipped with labview.

 

MLSD.png

It basically send the MLSD command, and wait for the reply. After that, it's a matter of parsing the reply of the server which, on my FTP, looks like this:

type=cdir;sizd=3;modify=20150220090455;UNIX.mode=0705;UNIX.uid=32210;UNIX.gid=100;unique=d8g863beb0; .
type=pdir;sizd=5;modify=20150302165245;UNIX.mode=0705;UNIX.uid=32210;UNIX.gid=100;unique=d8g863beae; ..
type=dir;sizd=12;modify=20150302000236;UNIX.mode=0705;UNIX.uid=32210;UNIX.gid=100;unique=d8g863beb2; Camera pile 9

 Regards,

 

peper

Message 10 of 13
(12,135 Views)