Results 1 to 7 of 7
Thread: listing files at the FTP
- 10-10-2010, 12:32 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 9
- Rep Power
- 0
listing files at the FTP
hi, i've just begun the java. And i want to file information (name, date or md5) on FTP server. I succeed to upload to FTP server.
but, i can't download and get file information.
i use sun.net.ftp.FtpClient library for upload file.
how i can list file and get information (date, name) ?
Thanks.
- 10-10-2010, 12:43 AM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
you can use the method list(), that returns a TelnetInputStream.
You could print the return e.g. with the Scanner class
you will receive the date, size, name etc.Java Code:Scanner sc = new Scanner(ftpClient.list()); while(sc.hasNextLine()){ System.out.println(sc.nextLine()); }
with cd(String s) you can change the directory
with get(String s) you will get a TelnetInputStream too and you can download the file
- 10-10-2010, 12:55 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
sun.net.ftp.FtpClient
Does this class still exist? Back when it used to the advice commonly given about using *any* of the sun. packages was: "Don't. They aren't portable and they aren't supported."
You might want to consider Apache's FTP client which is part of Apache Commons (Commons Net - Jakarta Commons Net) or some other Java ftp client.
- 10-10-2010, 01:07 AM #4
Member
- Join Date
- Oct 2010
- Posts
- 9
- Rep Power
- 0
the codes are follows. werite "abc" on terminal and nothing anything.
i check on filezilla and i see uploaded the file , but not listed in the directory.
Java Code:public void uploadDumpFiles2Server(){ String server="ftp.domain.tr"; String user="username"; String password="password"; String path="/httpdocs"; String filename="user.props"; try { FtpClient ftpClient=new FtpClient(); ftpClient.openServer(server); ftpClient.login(user, password); if (path.length()!=0) ftpClient.cd(path); ftpClient.binary(); TelnetOutputStream os=ftpClient.put(filename); File file_in=new File(filename); FileInputStream is=new FileInputStream(file_in); byte[] bytes=new byte[1024]; int c; while ((c=is.read(bytes))!=-1){ os.write(bytes,0,c);} is.close(); Scanner sc = new Scanner(ftpClient.list()); while(sc.hasNextLine()){ System.out.println(sc.nextLine()); } os.close(); ftpClient.closeServer(); } catch (IOException ex) {; System.out.println(ex.toString()); }
- 10-10-2010, 01:57 AM #5
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
mhm..I have tested your posted code and it works fine when I put the line os.close(); before the line Scanner sc = new Scanner(ftpClient.list());
But I agree with pbrockway2 you should not use the sun packages if possible(see:FAQ - Sun Packages)
- 10-10-2010, 10:05 AM #6
Member
- Join Date
- Oct 2010
- Posts
- 9
- Rep Power
- 0
Thanks. But 've a problem. download apache coomon file.
but, how to i import this library ?
I tried something but could not succeed.
- 10-10-2010, 11:30 AM #7
Member
- Join Date
- Oct 2010
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
Listing Installed DSA
By anoopasta in forum XMLReplies: 1Last Post: 05-06-2010, 04:10 PM -
Recursively listing files in a directory accepted as a string??
By Zxcvtypo in forum New To JavaReplies: 8Last Post: 11-20-2009, 09:33 PM -
Listing subdirectories/files with filter
By Java Tip in forum Java TipReplies: 0Last Post: 01-13-2008, 07:20 AM -
Listing subdirectories/files
By Java Tip in forum Java TipReplies: 0Last Post: 01-13-2008, 07:19 AM -
Listing all available Locales
By Java Tip in forum Java TipReplies: 0Last Post: 12-29-2007, 04:54 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks