• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

File upload using FTP

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic