I am doing a file transfer client server program and I need to be able
to change to a directory on the server to do an "ls" to list the
directory files then transfer file(s) from server to client.
> >I am wondering why I cannot change the directory using my java program
> > like so:
[quoted text clipped - 10 lines]
> Process proc = runtime.exec("ls" + ..., new String[0], new
> File("/home/user"));
hiwa - 25 Oct 2006 02:59 GMT
> I am doing a file transfer client server program and I need to be able
> to change to a directory on the server to do an "ls" to list the
> directory files then transfer file(s) from server to client.
You don't need to change directory to do that -- listing files in a
directory and send one of them.
Thomas Kellerer - 25 Oct 2006 12:21 GMT
> I am doing a file transfer client server program and I need to be able
> to change to a directory on the server to do an "ls" to list the
> directory files then transfer file(s) from server to client.
Why do you start a new process to list the files in a directory?
Have a look at File.listFile():
File dir = new File("/path/to/directory");
File[] filesInDir = dir.listFile();
Thomas
Martin Gregorie - 25 Oct 2006 22:01 GMT
> I am doing a file transfer client server program and I need to be able
> to change to a directory on the server to do an "ls" to list the
> directory files then transfer file(s) from server to client.
Have you considered using a Java SSH client class to talk to a standard
ftpd or sshd server?
Java class libraries exist to implement the client end of an FTP
connection which would connect to a standard ftpd server and should do
everything you need, though its relatively insecure. See:
http://jakarta.apache.org/commons/net/api/org/apache/commons/net/ftp/FTPClient.html
If you need higher security, e.g. encrypted passwords and files in
transit you should look at SSH. A full SSH implementation supports the
scp facilities for file transfer as well as the sftp facilities which
are a close approximation to FTP in terms of directory listing, moving
around the directory tree and moving files to or from the server, but
encrypt files during transfer. See http://linuxmafia.com/ssh/java.html
for information on available class libraries.
Using either FTP or SSH will save you a shed load of work because the
servers are standard, tested off the shelf code and have been ported to
almost every OS capable of supporting them.

Signature
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |