FTP with Java



Yes. That's what I did. Compilation was achieved with some
corrections.

However I had problems knowing which place to put my class or jar file
in.
So I have tried with the place where I found jt400.jar
(\\cgam\QIBM\ProdData\HTTP\Public\jt400\lib\) and
I've specified CLASSPATH var with value
'\QIBM\ProdData\HTTP\Public\jt400\lib\:\QIBM\ProdData\HTTP\Public\jt400\lib\jt400.jar'.
I hope I will have a simpler way to set this in fututre.

Now I have a problem with FTP execution : It seems that
- I can't retrieve anything else than a SAVF.
- I can't delete things on the remote system : trying the method
issueCommand with lots of values (DEL DLT RM RMV CLR...).
Can someone give help?

Here is the code I use :
import com.ibm.as400.access.*;

class FTPRm1stGetNext {
/*
* The object of this class is to start a connection to a FTP
server,
* providing a site name, user and password (1st, 2nd and 3rd
arguments),
* go to the specified directory (5th argument) and retrieve the
first file
* found in that directory to a specified place on the local machine
(4th
* argument).
*
* When we execute this class several times, we want it to delete a
file
* we may have already retrieved, before retrieving the next one. To
allow
* this, we provide the delete boolean (6th argument - true if not
empty).
*/

private static FTP ftp;
private static short step;

public static boolean process(String[] args) {
boolean delete=false;
String site="";
String user="";
String pass="";
String localname="";
String dir="/";
String rmCmd="del";
String[] f;

step=0; /* parse the args */
try {
site=args[0];
user=args[1];
pass=args[2];
localname=args[3];
if(args.length>4) {
dir=args[4];
delete=(args.length>5 && !args[5].equals("")); } }
catch(Exception e) { return false; }
try { rmCmd=args[6]; } catch(Exception ee) { }

step=1; /* connect */
ftp=new FTP(site, user, pass);
try { ftp.connect(); }
catch(Exception e) { return false; }

step=2; /* cd */
try { ftp.cd(dir); }
catch(Exception e) { return false; }

step=3; /* ls */
try { f=ftp.ls(); }
catch(Exception e) { return false; }

if(f.length>2) {
if(delete) { /* rm 1st */
step=4;
System.out.println("pass "+f[0]+" and "+f[1]+" - "+rmCmd+"
"+f[2]);
try { System.out.println(ftp.issueCommand(rmCmd+" "+f[2]));
}
catch(Exception ez) { return false; }
step=5; /* re-ls */
try { f=ftp.ls(); }
catch(Exception e) { return false; } }

if(f.length>2) { /* get 1st */
step=6;
System.out.println("pass "+f[0]+" and "+f[1]+" - get
"+f[2]+" "+localname);
try { System.out.println(ftp.get(f[2], new IFSJavaFile(new
AS400(), localname))); }
catch (Exception e) { return false; } } }

try { ftp.disconnect(); }
catch(Exception e) { return false; }
return true; }

public static void main(String[] args) {
if(!process(args)) {
System.out.println("FTPRm1stGetNext error at step "+step);
if(step>0)
System.out.println(ftp.getLastMessage());
System.out.println("usage: java FTPRm1stGetNext (<site> <user>
<passwd> <localname> [<dir> [D]]"); } }

.



Relevant Pages

  • Java compilation
    ... In order to execute my class, ... The object of this class is to start a connection to a FTP ... go to the specified directory and retrieve the ... we provide the delete boolean (6th argument - true if not ...
    (comp.sys.ibm.as400.misc)
  • Re: Unable to abort a FTP command?
    ... I write the following script to retrieve a part of a large file ... def login: ... print 'ftp handle closed' ... elif not chunk: ...
    (comp.lang.python)
  • Re: retrieve files from VxWorks
    ... I need to login using ftp to the target to ... retrieve one file. ... I added the int myAuthenticateCallback (Ipftps_session * session, ...
    (comp.os.vxworks)
  • Re: Using a Callback Function - ftplib
    ... attempting to connect to an FTP server, retrieve a list of files, and ... The result is even captured in an array. ... have no idea what the difference between a LIST and NLST is within ... FTP. ...
    (comp.lang.python)