aspose file tools
The moose likes Sockets and Internet Protocols and the fly likes File upload using FTP Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "File upload using FTP" Watch "File upload using FTP" New topic
Author

File upload using FTP

thejaswini ramesh
Ranch Hand

Joined: Oct 19, 2005
Posts: 74
Hi Everyone,

I need to implement a file upload functionality to a remote system using FTP. I did not find any API in java, so should I use some Third party Library? Can someone give me some help on how to go about it?

Thanks in Advance,
Thejaswini.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35258
    
    7
The Apache Jakarta Commons Net library contains a client-side FTP API.


Android appsImageJ pluginsJava web charts
thejaswini ramesh
Ranch Hand

Joined: Oct 19, 2005
Posts: 74
Thanks Ulf!

Is there an alternative to using the FTP API? I mean can I open a Socket on port 21 and do the same? I basically need to open an ftp connection to a system, browse to particular directory based on user input, change the mode to binary and upload the file there. Can you suggest a way to do it without using the API?

Thanks in advance,
Thejaswini.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35258
    
    7
Of course you can implement the FTP protocol on top of Java sockets yourself. But that's a non-trivial undertaking - why would you do that when a library that does that exists already?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8265

It is possible to do basic FTP (upload, download, indexing) using the java.net.URL class, as explained in our FileUpload FAQ


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
thejaswini ramesh
Ranch Hand

Joined: Oct 19, 2005
Posts: 74
Originally posted by Ulf Dittmer:
Of course you can implement the FTP protocol on top of Java sockets yourself. But that's a non-trivial undertaking - why would you do that when a library that does that exists already?


Thanks Ulf, Joe

I would use an already existing library but my boss wants me to it with sockets

:roll:

Will try with URL class.
Richard Waldicott
Greenhorn

Joined: Jun 10, 2007
Posts: 9
Wow, your boss is a tough customer. FTP protocol can get complicated, especially in dealing with passive connections and parsing directory listings, not to mention the additional things you need to do if you want to support FTPS (FTP over SSL). If you can, I would try and convince your boss to go with an existing API that has solved these problems.

you might look at the following.

http://www.jscape.com/sftp/
thejaswini ramesh
Ranch Hand

Joined: Oct 19, 2005
Posts: 74
Hi everyone,

I have used an FTP library from apache:
org.apache.commons.net.io
org.apache.commons.net.ftp

to do the file transfer. But I need to use the QUOTE command to do a reboot to the system after file transfer. I tried looking for a library which supported that, but did not find any. Can anyone suggest a library which supports the QUOTE command?

Thanks in advance,
Thejaswini.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35258
    
    7
The QUOTE command is used for sending raw FTP commands -instead of using the facilities of the client program/library- but FTP has no provisions for rebooting a server, nor should that be a required thing to do after a file transfer. What exactly are you trying to do?
thejaswini ramesh
Ranch Hand

Joined: Oct 19, 2005
Posts: 74
Thanks Ulf!

My FTP server is actually a device and I have to upload new software to a particular card. Once the upload is done I need to restart the card with a command like quote boot for the new changes to be effective. This is the reason i need QUOTE. How can I do this?



Thejaswini.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35258
    
    7
FTP has no provisions for executing arbitrary system commands. You'll need to find some other of sending commands to the device. Does it support Telnet or SSH?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

I use "RCMD" to get my FTP server to execute pretty much arbitrary commands. Typically after I upload a file I then want to run a program that takes that file and processes its contents.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: File upload using FTP
 
Similar Threads
how to execute ftp commands from java
asp
execute ftp commands using java API
uploading files in JSP
Urgently Need Help.....