HP3000-L Archives

August 2003, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Lars Appel <[log in to unmask]>
Reply To:
Lars Appel <[log in to unmask]>
Date:
Tue, 12 Aug 2003 09:55:05 +0200
Content-Type:
text/plain
Parts/Attachments:
text/plain (155 lines)
Mark Wonsil wrote:

>I've heard of folks using the FTP capability in Perl to control ftp
transfers.

Well, and then there is also the option of using Java ;-)

I recall having posted a small example on a different ftp thread in
the past, but it seems that it didn't make it into the Google archives
of HP3000-L. It can only be found on Raven itself...

 http://raven.utc.edu/cgi-bin/WA.EXE?A2=ind0306C&L=hp3000-l&P=R6910

Hmmm. On a second thought... I'm attaching a copy of the old posting,
so maybe it makes it into the archives for keyword search this time.

;-)

Back on the subject of EXITONERROR... you might want to make sure
that your new machine is on the latest FTP patches, depending on the
MPE/iX version you have installed.


- - - cut here - - -

D.H. Floyd wrote:

 >We are having some trouble with spaces in FTP "file names".
  ...
 >Anyone know how to send a space at this location in the string?


 Well, if nothing else helps, you could use a custom FTP client
 instead of the one supplied by MPE/iX. One option would be using
 a Java based one (as Java comes with MPE/iX). Other list members
 will probably share a Perl or Python based solution soon ;-)

 Here is a little FTP example that connects to a Unix machine,
 retrieves a list of filenames via DIR and then gets those files
 to MPE in ASCII mode. As I have used filenames with spaces on
 the Unix side, it stores the files as file0, file1, ... on MPE.

 The example uses an Open Source FTP client implementation that
 can be found at http://www.enterprisedt.com/downloads/ftp.html
 (which I just looked up today with a Google search, so I cannot
 share experiences with it beyond the example below).

 Oh, the example is quick & dirty, no extensive error checking.


 :setvar classpath, ":/APPEL/TEST/ftp-1.2.2/ftp.jar"

 :javac FtpDemo1.java

 :java FtpDemo1 unix.example.com lappel secret /tmp/my-dir
 file0 <- my file one
 file1 <- my file two

 :listfile ./file# ,2

  CODE  ------------LOGICAL RECORD-----------  ----SPACE----  FILENAME
          SIZE  TYP        EOF      LIMIT R/B  SECTORS #X MX

            1B  BA           4 2147483647   1       16  1  *  file0
            1B  BA           4 2147483647   1       16  1  *  file1

 :purge ./file# ;noconfirm

 :java FtpDemo1 unix.example.com lappel secret my-dir debug
 file0 <- my file one
 file1 <- my file two
 ---> USER lappel
 331 Password required for lappel.
 ---> PASS ********
 230 User lappel logged in.
 ---> CWD /tmp/my-dir
 250 CWD command successful.
 ---> PASV
 227 Entering Passive Mode (xx,xxx,xx,xxx,xxx,xxx)
 ---> NLST
 150 Opening ASCII mode data connection for file list.
 226 Transfer complete.
 ---> TYPE A
 200 Type set to A.
 ---> PASV
 227 Entering Passive Mode (xx,xxx,xx,xxx,xxx,xxx)
 ---> RETR my file one
 150 Opening ASCII mode data connection for my file one (4 bytes).
 226 Transfer complete.
 ---> PASV
 227 Entering Passive Mode (xx,xxx,xx,xxx,xxx,xxx)
 ---> RETR my file two
 150 Opening ASCII mode data connection for my file two (4 bytes).
 226 Transfer complete.
 ---> QUIT
 221 Goodbye.

 :# oops, before I forget... here is the java source code ;-)

 :print ./FtpDemo1.java

 // Usage: java FtpDemo1 host user pass dir ["debug"]

 import com.enterprisedt.net.ftp.FTPClient;
 import com.enterprisedt.net.ftp.FTPTransferType;

 import java.io.ByteArrayOutputStream;
 import java.io.PrintWriter;

 class FtpDemo1
 {
   public static void main(String[] args)
     throws Exception
   {
     ByteArrayOutputStream log = new ByteArrayOutputStream();

     FTPClient ftp = new FTPClient(args[0]);

     ftp.setLogStream(new PrintWriter(log));
     ftp.debugResponses(args.length > 4);

     ftp.login(args[1],args[2]);

     ftp.chdir(args[3]);

     String[] dir = ftp.dir();

     for (int k=0; k < dir.length; k++) {
       System.out.println("file" + k + " <- " + dir[k]);
     }

     ftp.setType(FTPTransferType.ASCII);

     for (int k=0; k < dir.length; k++) {
       ftp.get("file" + k, dir[k]);
     }

     ftp.quit();

     log.writeTo(System.out);
   }
 }


 Notice that Java, like other Posix applications on MPE, creates its
 output files (file0 and file1 on the above example) in bytestream
 format (with LF as line delimiter). Many MPE programs can read those
 just like they would read a Fixed Ascii format, for example. If not,
 you might need to use /bin/frombyte to convert to 80B FA.

 Lars.

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2