• Post Reply Bookmark Topic Watch Topic
  • New Topic

File upload using FTP  RSS feed

 
thejaswini ramesh
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Apache Jakarta Commons Net library contains a client-side FTP API.
 
thejaswini ramesh
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is possible to do basic FTP (upload, download, indexing) using the java.net.URL class, as explained in our FileUpload FAQ
 
thejaswini ramesh
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!