|
Bill-FileSystemOptions();
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 = opts;//SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fil
//fileSystemOptions = opts;
"no");//FtpFileSystemConfigBuilder.getInstance().setDataTimeout(opts, 100);
FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fileSystemOpti
false);FtpFileSystemConfigBuilder.getInstance().getUserDirIsRoot(fileSystemOpti
//FileSystemConfigBuilder config =
(FileSystemConfigBuilder)FtpFileSystemConfigBuilder.getInstance();
boolean tmp =
System.out.println("Setting for 'UserDirIsRoot':" + tmp);
//locate the local file by nameby name");
System.out.println("Now locate the local file
String strLocalFile ="C:\\sgladstone\\edfiles\\" + "datafile";
FileObject foLocalFile =mgr.resolveFile(strLocalFile);
by name");
// locate the remote file by name
System.out.println("Now locate the remote file
"ftp://myuserprofile:mypassword@myas400hostname/home/aplsup/sarahtest.tx
String rUrlStr =
;rUrlStr, opts);
FileObject foRemoteFile = mgr.resolveFile(
exists");
if(foRemoteFile.exists()){
System.out.println("Remote file
}else{NOT exist");
System.out.println("Remote file does
}remote file.
FileSelector fS = Selectors.SELECT_SELF ;
// Copy the contents of the local file to the
// ie upload the file to the servertry copyFrom cmd");
if (foLocalFile.exists()){
System.out.println("local file exists,
foRemoteFile.copyFrom(foLocalFile, fS);exist. Nothing to upload. ");
}else{
System.out.println("Local file does not
}FileSystemManager");
}catch (Exception e) {
e.printStackTrace();
}finally {
System.out.println("Now close the
if( mgr != null) ((DefaultFileSystemManager)mgr).close();
}wrote:
}
/**
* @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>
evenGood morning Sarah
Apache VFS uses Jakarta Commons Net for the FTP part.
With luck the Net part will take initialization parameters, and may
and Ihave a console which could show the dialog between the client and
server.
I've downloaded the source for these projects because I am curious
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.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.