Software development, photography, jokes, ....


Sites by me

tas-logoTransportation Administration System
snoezelkussen-logo-kleinstSnoezelen Pillows for Dementia
ikzoekeenbegeleider-logoBegeleiders voor gehandicapten
Laat uw hond het jaarlijkse vuurwerk overwinnen
Betuweroute en Kunst
logo 50x50Hey Vos! Je eigen emailadres?
Kunst in huis? Nicole Karrèr maakt echt bijzonder mooie dingen
nettylogo2Kunst in huis? Netty Franssen maakt ook bijzonder mooie dingen

Hosting Favorites

ANU Internet Services
XEL Media


Google Translate
jQuery UI
YourHead Stacks API
Favicon Generator.
Password Generator.
Check HTTPS problems

Marc's Place


 FTP with Lasso

  Various methods examined

This post is about the various ways to use the FTP protocol with Lasso, from and to various systems, like Windows, CentOS or IBM iSeries. I have been trying to get it work and now that it does, I wanted to share what you can do. Of course there are probably installations where it all works out-of-the-box, but this time not with me.

Buy me a coffee-1

So how do you transfer a file per ftp with Lasso? Well, before you do, you have to check off a list:

1.  Am I behind a firewall?

If so, check with your sysadmin for the following:
a) Is outbound ftp allowed? If not, your netadmin should allow it for the computer you will be sending files from.
b) Are all ports above 1023 freely accessible for PASV mode? You need to have that, because Lasso uses libcurl, of which the standard mode is PASV. If not, your netadmin should allow it for the computer you will be sending files from.

2.  Is the ftp server on the computer you will be sending files to, running?

3.  Check the connection by starting a terminal cq. command prompt session and type the following command:

ftp <ip-address or DNS name of server>

If you get a prompt for a username, the connection can be established.

4.  Log on via the in (3) established connection. Type the following command:


The current directory on the server, where you landed after you logged in, is listed. If this is the directory where you want to send files to, go to step 5. If it is not, navigate to a subfolder or sharepoint by using the command:

cd /some/remote/folder/

5.  Send a file. Navigate to the local directory you want to send files from, by using the command:

lcd /some/local/folder/

If you are in the right directory, transfer a file:

put <filename>

If you get any errors, check the permissions of:

     - the file: may you read it?
     - the directory on the server: may you write to it?

6.  Example transfer:

testuser @ ~ $ ftp
Connected to
220-Welcome to anXserve
220-This is a private system.
220-No anonymous access possible.
220 anXserve FTP server ready.
Name ( testuser
331 Password required for testuser.
230-You are now logged in
230 User testuser logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
Remote directory: /
ftp> ls
227 Entering Passive Mode (82,93,29,20,43,171)
150 Opening ASCII mode data connection for directory listing.
total 8
drwxr-xr-x   2 testuser  testuser    68 Aug  3  2009
drwx------   9 testuser  testuser   306 May 15  2008 Desktop
drwx------  14 testuser  testuser   476 Jul  6 00:28 Documents
drwxr-xr-x   3 testuser  testuser   102 Feb 22 15:22 Downloads
drwxrwxr-x   1 testuser  testuser   306 Feb 18 13:32 FTPRoot
drwx------  30 testuser  testuser  1020 Oct 14  2009 Library
drwx------   3 testuser  testuser   102 Jan 20  2006 Movies
drwx------   4 testuser  testuser   136 Nov 25  2007 Music
drwx------   4 testuser  testuser   136 Feb 18 12:30 Pictures
drwxr-xr-x   5 testuser  testuser   170 Sep  4  2009 Public
drwxr-xr-x   2 testuser  testuser    68 Jun 23 17:43 Sites
226 Transfer complete.
ftp> cd downloads
250 CWD command successful.
ftp> ls
227 Entering Passive Mode (82,93,29,20,43,180)
150 Opening ASCII mode data connection for directory listing.
226 Transfer complete.
ftp> lpwd
Local directory: /Users/testuser
ftp> lcd downloads
Local directory now: /Users/testuser/Downloads
ftp> !
testuser @ ~/Downloads $ echo Hello > hw.txt
testuser @ ~/Downloads $ ls
testuser @ ~/Downloads $ cat hw.txt
testuser @ ~/Downloads $ exit
ftp> bin
200 Type set to I.
ftp> put hw.txt
local: hw.txt remote: hw.txt
227 Entering Passive Mode (82,93,29,20,44,16)
150 Opening BINARY mode data connection for directory listing.
100% |***************************************************************************************|     6       44.72 KiB/s    00:00 ETA
226 Transfer complete.
6 bytes sent in 00:00 (0.08 KiB/s)
ftp> ls
227 Entering Passive Mode (82,93,29,20,44,19)
150 Opening ASCII mode data connection for directory listing.
total 8
-rw-r--r--  1 testuser  testuser  6 Jul 10 17:03 hw.txt
226 Transfer complete.
ftp> close
221-You have transferred 6 bytes in 1 files.
221-Total traffic for this session was 215 bytes in 1 transfers.
221-Thank you for using the FTP service on anXserve.
221 Goodbye.
ftp> quit
testuser @ ~ $

Now that we know that transfers to our Unix server work, we can code a Lasso page with an ftp statement in it. Here are the two statements you can use.

Note 1: Windows is case insensitive, most OS X installations are case insensitive but some are not, CentOS is case sensitive. What does this mean for you? It means that you must always only use lowercase for file and folder names and that file or folder names of others need to be typed exactly as they are named. Thus: 'downloads' and 'Downloads' are seen as two different directories on case-sensitive systems, like CentOS and RHL.

Note 2: To be sure that os_process works, always use full paths in its parameters. For example, on a command prompt you can type ipconfig and it runs. But in os_process you have to specify the full path. On Windows, it is '/windows/system32/ipconfig.exe' and on unix it is '/usr/sbin/ipconfig'.

Note 3: In the examples we assume that the Lasso file is saved in the webserver's root. On Windows, with IIS, that will be 'c:\inetpub\wwwroot\' (you might configure Apache so that it serves from this directory too); on OS X it will be '/library/webserver/documents/' and on CentOS or RHL it is '/var/www/html/'.

From Windows  to  Unix or Windows:

     'myFile' = 'test.txt', 
     'myURL' = ''

ftp_putfile (-url=$myURL + $myFile, -file=$myPath + $myFile, -username='testuser', -password='testpassword');

From OS X  to  Unix or Windows:

     'myFile' = 'test.txt', 
     'myURL' = ''

ftp_putfile (-url=$myURL + $myFile, -file=$myPath + $myFile, -username='testuser', -password='testpassword');

From CentOS or OS X  to  Unix:

     'myFile' = 'test.txt', 
     'myURL' = '',

     'myProcess' = '',
     'theError' = '',
     'theResult' = ''

$myProcess = os_process('/bin/bash', array('-c', 'cd ' + response_localfolder + '; ' + '/usr/bin/curl -T' + $myPath + $myFile + ' -u testuser:testpassword ' + $myURL));
$theError' = encode_html($myProc->readError);
$theResult' = encode_html($myProc->readString);

There is a tag on TagSwap called shell, which does these 4 statements and makes it easier for you:

$theResult = shell('/usr/bin/curl -T' + $myPath + $myFile + ' -u testuser:testpassword ' + $myURL);

From Windows to iSeries' or AS/400's native file system (not STRQSH)

This is a special case, for two reasons: the file system on i5/OS is completely different from all other known file systems and it stores text in EBCDIC instead of ASCII.

iSeries' File System in short:

On iSeries, one has files too, of course. But ... here, a file is container of files, called members. Each member contains data. The file system has directories too, but ... here they are called libraries and cannot have subdirectories.


To send a member in one complete URL seems possible, but is not always easy to accomplish because of all kinds of assumptions systems make. Therefore you can do it like this:

a.  Create a file in /inetpub/wwwroot/ (the default IIS-serving folder) with answers to ftp-commands you normally type in yourself and call it iseriesftp.txt, or so. Here is an example:

cd ftp
put c:\windows\temp\hw.txt

b.  Create a DOS-batch file in /inetpub/wwwroot/ to run ftp and feed it the commands in the iseriesftp.txt file. Name this file iseriesftp.cmd:

cd c:\inetpub\wwwroot\
ftp -v -i -s:iseriesftp.txt

You have to cd into the directory where your file is, because Lasso's os_process always lands inside the Lasso application folder.

c.  Now go into your Lasso file and add the following statements:

     'myProcess' = '',
     'theError' = '',
     'theResult' = ''

$myProcess = os_process('c:/inetpub/wwwroot/iseriesftp.cmd');
$theError' = encode_html($myProc->readError);
$theResult' = encode_html($myProc->readString);

Note the forward slash! Although we are on Windows, Lasso is primarily written for Unix or Linux. Therefore you use the forward slash! Lasso converts it internally back into a backslash when it sees that it runs on Windows.

The funny thing is that this process will result in a file called TXT, in Library FTP, with a member called HW! So if you want to name your files and members clearly on iSeries' native file system, remember that the file you send should be named like so: <membername>.<filename>. Names can only have a maximum of 10 characters and do not use any special characters, except '$', '#' and the '_'. 
In the above screenshot we have a file call ZSAP with two members. These members come from a Unix or Windows system and are plain ASCII text files, named like this: Z003435699.ZSAP and Z003434701.ZSAP.

To be able to use any non-standard extension, I added * to Setup -> Site -> File Extensions in SiteAdmin.

buy me something-2
© 1997- Marc Vos (and others)   -   Privacy Statement   -    Contact Me

On this website, Google Analytics is used to track visitor statistics. These are anonymised data about the number of visitors, which pages they visit on this site, from which regions they visit, which web browsers they use, etc.. You will also see non-personalised ads via Google AdSense. Cookies from Paddle or Paypal are placed when you click on a 'Buy now!' or 'Donate!' button, and possible cookies from Disqus when you use that system to comment on one or more blogposts.
Privacy Statement