Sarah:
Got it!  This modification of your program works correctly on my system!
The part that got me was that file name on the i5 is very case
sensitive.
Work link shows the folder name as "/Blalock".
"/blalock/clean_debug.log" works if file is present in IFS but fails if
"clean_debug.log" is not there.  It tries to create a folder "/blalock"
and fails (thankfully!!!!)
"/Blalock/clean_debug.log" works either way.
Note that I added a check for the parent of the remote file.  The remote
file may or maynot be present, usually not I would guess.  The parent of
the remote file needs to be present.  My check assumes only one level
but you get the idea.
Your program tinkered with ....
Thanks for pointing this tool out!
Bill Blalock
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSelector;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.Selectors;
import org.apache.commons.vfs.VFS;
import org.apache.commons.vfs.impl.DefaultFileSystemManager;
import org.apache.commons.vfs.provider.ftp.FtpFileSystemConfigBuilder;
public class Ftptest2 {
	public Ftptest2() {
		// obtain a FileSystemManager instance
		FileSystemManager mgr = null;
		try {
			mgr = VFS.getManager();
			FileSystemOptions fileSystemOptions = new
FileSystemOptions();
			
	
FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(
					fileSystemOptions, false);
			
			boolean tmp =
FtpFileSystemConfigBuilder.getInstance()
	
.getUserDirIsRoot(fileSystemOptions);
			
			System.out.println("Setting for 'UserDirIsRoot'
:" + tmp);
			// locate the local file by name
			System.out.println("Now locate the local file by
name");
			String strLocalFile =
"C:/temp/logs/clean_debug.log";
			FileObject foLocalFile =
mgr.resolveFile(strLocalFile);
			if (foLocalFile.exists()) {
				System.out.println("Local file exists");
			} else {
				System.out.println("Local file does NOT
exist");
			}
			// locate the remote file by name
			System.out.println("Now locate the remote folder
and file by name");
			String rUrlStr =
"
ftp://BLALOCK:XXXXXXXX@MYSYSTEM/Blalock/clean_debug.log";
			FileObject foRemoteFile =
mgr.resolveFile(rUrlStr, fileSystemOptions);
			System.out.println("\tdebug ... Remote file: " +
foRemoteFile.getName().getPath() );
			System.out.println("\tdebug ... Parent of remote
file: " + foRemoteFile.getParent().getName().getPath() );
			
			if (foRemoteFile.getParent().exists()) {
				System.out.println("Remote parent folder
exists");
			} else {
				System.out.println("Remote parent folder
does NOT exist");
			}
			if (foRemoteFile.exists()) {
				System.out.println("Remote file
exists");
			} else {
				System.out.println("Remote file does NOT
exist");
			}
			FileSelector fS = Selectors.SELECT_SELF;
			System.out.println("");
			// Copy the contents of the local file to the
remote file.
			// ie upload the file to the server
			if ( foRemoteFile.getParent().exists() ) {
				if (foLocalFile.exists()) {
					System.out.println("Local file
exists, try copyFrom cmd");
	
foRemoteFile.copyFrom(foLocalFile, fS);
				} else {
					System.out
							.println("Local
file does not exist. Nothing to upload. ");
				}
			} else
				System.out
				.println("Remote parent folder does not
exist. Nothing to receive upload. ");
				
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			System.out.println("Now close the
FileSystemManager");
			if (mgr != null)
				((DefaultFileSystemManager)
mgr).close();
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new Ftptest2();
		System.out.println("Now exit main");
	}
}
-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx
[mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of Sarah Poger
Gladstone
Sent: Sunday, October 26, 2008 8:02 AM
To: Java Programming on and around the iSeries / AS400
Subject: Re: Using Apache VFS to FTP to the AS/400 IFS
Bill- Were you able to use my simple Java class to try out an FTP
upload with Apache VFS?
-Sarah
On Thu, Oct 23, 2008 at 6:02 PM, Sarah Poger Gladstone
<listmember@xxxxxxxxxxxxxx> wrote:
Bill-
Below is a Java class with a main method that I am using for testing
an FTP upload using the VFS APIs.
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSelector;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.Selectors;
import org.apache.commons.vfs.VFS;
import org.apache.commons.vfs.impl.DefaultFileSystemManager;
import org.apache.commons.vfs.provider.ftp.FtpFileSystemConfigBuilder;
public class Ftptest1 {
       public Ftptest1() {
   //  obtain a FileSystemManager instance
               FileSystemManager mgr = null;
               try {
                       mgr = VFS.getManager();
                       FileSystemOptions fileSystemOptions;
                       FileSystemOptions opts = new
FileSystemOptions();
                       fileSystemOptions = opts;
                       //fileSystemOptions = opts;
//SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fil
eSystemOptions,
"no");
//FtpFileSystemConfigBuilder.getInstance().setDataTimeout(opts, 100);
FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fileSystemOpti
ons,
false);
                       //FileSystemConfigBuilder config =
(FileSystemConfigBuilder)FtpFileSystemConfigBuilder.getInstance();
                       boolean tmp =
FtpFileSystemConfigBuilder.getInstance().getUserDirIsRoot(fileSystemOpti
ons);
                       System.out.println("Setting for 'UserDirIsRoot'
:" + tmp);
                       //locate the local file by name
                       System.out.println("Now locate the local file
by name");
                       String strLocalFile =
"C:\\sgladstone\\edfiles\\" + "datafile";
                       FileObject foLocalFile =
mgr.resolveFile(strLocalFile);
//                      locate the remote file by name
                       System.out.println("Now locate the remote file
by name");
                       String rUrlStr =
"
ftp://myuserprofile:mypassword@myas400hostname/home/aplsup/sarahtest.tx
t"
;
                       FileObject foRemoteFile = mgr.resolveFile(
rUrlStr, opts);
                       if(foRemoteFile.exists()){
                               System.out.println("Remote file
exists");
                       }else{
                               System.out.println("Remote file does
NOT exist");
                       }
                       FileSelector fS = Selectors.SELECT_SELF ;
//                       Copy the contents of the local file to the
remote file.
//                       ie upload the file to the server
                       if (foLocalFile.exists()){
                               System.out.println("local file exists,
try copyFrom cmd");
                               foRemoteFile.copyFrom(foLocalFile, fS);
                       }else{
                               System.out.println("Local file does not
exist. Nothing to upload. ");
                       }
               }catch (Exception e) {
                       e.printStackTrace();
               }finally {
                       System.out.println("Now close the
FileSystemManager");
                       if( mgr != null) ((DefaultFileSystemManager)
mgr).close();
               }
       }
       /**
        * @param args
        */
       public static void main(String[] args) {
                new Ftptest1();
                System.out.println("Now exit main");
       }
}
On Wed, Oct 22, 2008 at 8:49 AM, Blalock, Bill <Bill.Blalock@xxxxxxxx>
wrote:
Good morning Sarah
Apache VFS uses Jakarta Commons Net for the FTP part.
With luck the Net part will take initialization parameters, and may
even
have a console which could show the dialog between the client and
server.
I've downloaded the source for these projects because I am curious
and I
will learn things applicable to my projects.
Could you send me a stand alone sample program which transfers using
FTP?
Bill B
As an Amazon Associate we earn from qualifying purchases.