Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FTP password

 
Eugene Max
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I am creating an application that will upload a local file to an FTP site. The FTP server needs account and password to be accessed. How do I write the password inside the code?
myaccount@ftp://oursite.com ?mypassword?
Thanks,
Eugene
 
Lewin Chan
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, it's considered bad practice to put the password directly into the URL string, however, you can do
ftp://username:password@site.com:port/directory.
You can get the username and password out using a java.net.URL.getUserInfo() which will return you "username:password"
Alternatively, if you use javax.mail.URLName (from JavaMail api) you can do URLName.getUsername(), and URLName.getPassword()

 
Eugene Max
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot... It's a big help...
Eugene
 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,Eugene Max
Can you tell me how are you uploading the file using FTP in java.
I have to do exactly the same thing in my module.
thanks,
Trupti

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic