With the first (Beta 1) simulator this could be done using FTP. The simulator had little in the way of security: all apps ran as "root" and you could log in via Telnet or FTP as the root user. They didn't even make any attempt to make the password difficult to guess!
Unfortunately, with the Beta 2 simulator, they've tightened up security substantially. This is overall a good thing, since the final release should be very secure so we need to test under the same conditions, but it has hampered some testing efforts.
So in Beta 2, they removed Telnet and FTP, and added Secure Shell (SSH) access. Hurray! Except... what you can do with it is very limited due to several bugs, for now.
While SSH normally supports scp or sftp, someone at QNX got a bit creative with security and made /etc/passwd unreadable to non-root users. This has the unfortunate side-effect of breaking scp and sftp as I discovered. It's also entirely unnecessary because, in spite of its name, /etc/passwd is not a password file. It used to be, but in modern times the password hashes have all been moved to /etc/shadow, which of course is not readable by regular users.
There's another problem which makes things difficult, even if you figure out how to transfer files using just SSH. They apparently intended to make an app's "sandbox" folder accessible to the development user when running in development mode (specifically, with the -devMode option on blackberry-airpackager). It looks like that doesn't actually work either -- at least, I can't get it to work, and no one else reports success yet either. When you log in with SSH, you become "devuser" (uid 100). Unfortunately the sandbox folders are all under /accounts/1000 and "devuser" cannot access or read any of them, even those for apps installed with that mystical -devMode option. [This was fixed in 0.9.3. -Ed]
I've found a few primitive workarounds so far. Depending on your needs, one or more of these may work:
Your app can of course access its own files (in File.applicationDirectory, which maps to /accounts/1000/appdata/MyAppName.MY-APP-ID-HASH/data. The simplest approach is not to use external access via SSH, but just bundle your files with your app, and provide app-specific ways of manipulating them. Use things like File.copyTo() in the simulator, or flash.net.FileReference to transfer files between your web server and the simulator. Doesn't help if you don't have a web server and don't know how to set one up, even locally.
Use basic command-line tools via SSH. This won't work well for binary data, but if you just need to get a text file into the sim, something like this will work when executed at the command line on your host machine:
# transfer myfile from simulator to host ssh devuser@MYSIMIP cat myfile >myfile # transfer myfile from host to simulator type myfile | ssh devuser@MYSIMIP "cat >myfile"
The first command executes "cat myfile" remotely on the simulator, and the output is redirected into a file on your host machine.
The second command outputs local myfile to stdout, piping it through SSH, and on the remote side redirects stdin to a new copy of myfile. That will end up in /accounts/devuser/myfile. To read this in your app, you'll need to do two things.
If you need to get files from the app, do chmod a+wrx ~ to make that folder writable as well as readable, and make sure your app writes to that folder rather than File.applicationStorageDirectory where it normally would.
Transfer files using FTP, with the simulator as the client, to the devuser home folder. You first need to run an FTP server outside the simulator. Log into the simulator using SSH and type "ftp MYHOSTIP" then log in to FTP. Transfer files the usual way, making sure to type "binary" to switch to binary mode for file transfers unless you're doing just text files.
If you're desperate to the file transfers, you could run Python2.7 on the simulator and use Python's ftplib module. In the old simulator you could just do "python2.7" but another minor issue in the new one means you have to use a full path of /base/usr/bin/python2.7. You can write a script that will, for example, run on the simulator side and maintain a mirror with periodic updates to keep things in sync. [In 0.9.4 they changed the permissions so "devuser" cannot run Python on the simulator, rather sadly for me. -Ed]
If you combine options 1 and 4, you can have a fully automated way of moving files between your app's storage directory and your host machine. Just set up a Timer, have it trigger some File.copyToAsync() calls to exchange files with the /accounts/devuser folder, and after logging in via SSH run a timed Python script to exchange files with your host machine. Crufty, but until the next release it's the best I can think of!
Well, that's it. There are always options...
Originally the post referred to this simulator version as "Beta 3" because we all thought that's what it was. As RIM seems to think confusing us is a good idea, they issued the Beta3 SDK with the Beta2 simulator even though both are called v0.9.2... Go figure!