Getting a File Listing From a Remote Computer

General discussion about Mathematica features and functionality...
Forum Rules
By using the Wolfram Faculty Program Forum, you agree not to post any abusive, obscene, vulgar, slanderous, hateful, threatening, or sexually oriented material. Wolfram Faculty Program Forum administrators have the right to remove, edit, move or close any topic at any time should we see fit.

Personal Information: Posts in this forum may be viewed by non-members; however, the forum prohibits non-members from viewing your profile. Although your email address is hidden from both non-members and members, your account is initially configured to allow members to contact you via email through the forum. If you wish to hide your profile, or prohibit others from contacting you directly, you may change these settings by updating your profile through the User Control Panel.

Attachments: Attachments are not currently enabled on this forum. To share a file with others on this site, simply upload your file to the online storage service of your choice and include a link to the file within your post. If your school does not offer an online file storage and sharing service, the following sites provide free basic online file storage and sharing: Mozy, FilesAnywhere, Adrive, and KeepandShare.

Getting a File Listing From a Remote Computer

Postby Gregory » Mon Sep 10, 2012 11:45 am

Hello everyone,

I'm creating CDF quizzes and assignments for my students. Because CDF does not permit exporting of data, I will have them copy their answers from a text cell and then use a web form or FTP client to upload the data to my server, which is a Mac at my office at work. I then want to use Mathematica to access and download those submissions from the Mac in my other office.

I know how to use Import with FTP to import a single file on my remote Mac, but how can I get a listing of all files in a folder on that Mac? I have tried

FileNames["*", dataFilePath]

where

dataFilePath is "user:password@computerAddress//Documents/FolderName/"

but, of course, FileName[...] does not make a connection, so it does not return anything.

Any tips?

Regards,

Gregory
User avatar
Gregory
 
Posts: 32
Joined: Wed Jul 27, 2011 3:13 pm
Location: Montreal
Organization: Concordia University
Department: Finance

Re: Getting a File Listing From a Remote Computer

Postby Kelvin_Mischo » Mon Sep 10, 2012 5:42 pm

Hi Gregory,

Excluding the CDF part for a minute, if there is a folder of files which you'd like to import and make a nested list in your machine, I'd suggest something like the following (which is taken out of an application I wrote):

SetDirectory["//sharedfiles.com/temp/SpecificAssignment/"];
results = Import[#] & /@ FileNames[]

This is similar to what you have below, so I think you are on the right track. In my example above, you can test the import of a single file first with no full file path to make sure the connection and path work, then build the loop based on finding all the file names in that particular folder. That should help you test the major steps to see what isn't working.

We're also starting to talk to people about special agreements to create custom-signed CDF documents. There are now options to give your students CDF documents that would export information from the CDF document which isn't possible with FreeCDF. It seems like this would have a couple advantages to you, it would eliminate the cut-and-paste step that you have in mind, and would also eliminate the need to build a web form that students would use just to shuffle information to you. Exporting results as a notebook is also really handy since it can be any sort of string, graphic, special function, or any Mathematica expression - when I'm building applications like this, it always takes a chunk of time to figure out how a string or XLS file is going to change information (change to numeric values and round values, etc) and how I'll need to filter it in Mathematica to check the expressions against correct answers or do some analysis. It's possible to import a notebook file and just peel out the data as a list of expressions.

If that's of interest, let me know, I'll have someone talk to you about this in more detail.

Kelvin
User avatar
Kelvin_Mischo
 
Posts: 12
Joined: Fri Sep 11, 2009 9:54 pm
Organization: Wolfram Research, Inc.
Department: Sales

Re: Getting a File Listing From a Remote Computer

Postby Gregory » Wed Sep 12, 2012 12:24 am

Kelvin_Mischo wrote:
SetDirectory["//sharedfiles.com/temp/SpecificAssignment/"];
results = Import[#] & /@ FileNames[]

Kelvin


He Kelvin,

Thank you for the tip. It is exactly what I am looking for, but unfortunately, I get the following error:

"SetDirectory::cdir: Cannot set current directory to..."

which apparently means that Mathematica cannot find or set the directory. However, the file path that I use works fine in my FTP client and other languages that I use. My file path for the remote Mac looks like this.

dataFilePath="username:password@myServer.domain.ca//Documents/folder1/folder2/";

I then executed

SetDirectory[dataFilePath]

and got the error described above. I also tried this form of the path

"username:password@myServer.domain.ca//Users/username/Documents/folder1/folder2/";

and got the same error. I'm guessing that Mathematica is not able to send a password like an FTP client does, or perhaps Mathematica uses SFTP by default, whereas I have FTP running on the remote Mac. I cannot keep the submissions in a public folder because there is other confidential information about student accounts. I suppose I could use LiveCode or a CGI to download the submissions to my local hard drive and then use Mathematica to process them, but it would be nice to be able to use Mathematica for all of the steps.

By the way, your other suggestions about signed CDFs is interesting.

Gregory
User avatar
Gregory
 
Posts: 32
Joined: Wed Jul 27, 2011 3:13 pm
Location: Montreal
Organization: Concordia University
Department: Finance

Re: Getting a File Listing From a Remote Computer

Postby Kelvin_Mischo » Fri Sep 14, 2012 6:07 pm

Hi Gregory,

I glossed over the fact that you are using FTP in this case, I don't have a lot of experience with this. I'll have someone get in touch with you to get this question routed to our Technical Support for a more complete answer. I'll also have the person that handles licensing for your campus explain the process of custom-signed CDF files in more detail as well so you know the best ways to share these documents.

thanks,
Kelvin
User avatar
Kelvin_Mischo
 
Posts: 12
Joined: Fri Sep 11, 2009 9:54 pm
Organization: Wolfram Research, Inc.
Department: Sales

Re: Getting a File Listing From a Remote Computer

Postby Gregory » Fri Sep 14, 2012 11:37 pm

Thank you, Kelvin. Much obliged.

Gregory
User avatar
Gregory
 
Posts: 32
Joined: Wed Jul 27, 2011 3:13 pm
Location: Montreal
Organization: Concordia University
Department: Finance

Re: Getting a File Listing From a Remote Computer

Postby Michael_Rogers » Sun Sep 16, 2012 2:33 pm

This is not a great solution....

StringSplit /@ Import["ftp://.../dir/", "List"]

FTP-ing a Unix system gave an "ls -l" directory listing. The post-processing above yielded a list of lists, a row for each file; the 9th column was the filename. This gave a list of the file names:

#[[9]] & /@ StringSplit /@ Import["ftp://.../dir/", "List"]

Obviously it depends on the output format of the FTP server. I couldn't get ftp to work with an old Mac.

Hope that helps,

Michael
User avatar
Michael_Rogers
 
Posts: 10
Joined: Mon May 24, 2010 3:28 pm
Organization: Emory University
Department: Oxford College

Re: Getting a File Listing From a Remote Computer

Postby Gregory » Sun Sep 16, 2012 5:12 pm

Hi Michel,

Thanks for the tip. I will tinker with it. I have no problem with parsing messy lists! If I can connect, the rest will fall into place.

Regards,

Gregory
User avatar
Gregory
 
Posts: 32
Joined: Wed Jul 27, 2011 3:13 pm
Location: Montreal
Organization: Concordia University
Department: Finance


Return to General Mathematica Discussion

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron