• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 827
  • Last Modified:

writing to an ftp server

I'm trying to write a program that writes a text file to an ftp server. I'm using this library "com.jscape.inet.ftp". But I'm getting an exception "com.jscape.inet.ftp.FtpException". I set up the server so that it is possible to write to it, so i do not know what the problem is.  
  Thanx in advance for looking it up.
0
krupini
Asked:
krupini
  • 7
  • 6
  • 3
  • +1
1 Solution
 
CEHJCommented:
You can simply do this, then you need no other libraries:

      public void writeToFileViaFtp() {
            try {
                  URL ftp = new URL("ftp://username:password@somewhere.com/somefile.txt");
                  URLConnection conn = ftp.openConnection();
                  conn.setDoOutput(true);
                  PrintWriter out = new PrintWriter(conn.getOutputStream());
                  out.println("Line 1");
                  out.println("Line 2");
                  out.close();
            }
            catch (Exception e) {
                  e.printStackTrace();
            }
      }
0
 
krupiniAuthor Commented:
Hi, this question is for CEHJ. Thanx for answering my question. However I still get an error when running your programm. It says "protocol doesn't support output". Would that be a problem with my server or the code?
I appreciate your help.
Thanx.
0
 
CEHJCommented:
That would probably be a username/password thing - code works fine for me
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
CEHJCommented:
(of course, you have to put *your* username and password in the url ;-))
0
 
mightyoneCommented:
;-)
0
 
krupiniAuthor Commented:
Hi, CEHJ. Yes i know it has to be my password and username. Here, i made a special loggon for you.
  ftp://try:trytry@69.194.83.97/asdsa.txt

"try" is the username and trytry is the  the password. the other is my IP.
Please try writting something to the file called "asdsa.txt". When do it it gives me the same error.
Again, I
0
 
krupiniAuthor Commented:
Aprreciate you help
0
 
CEHJCommented:
Oh sorry - missed the last bit. Just wrote a file up there called somefile.txt. Shall write to the other
0
 
CEHJCommented:
OK - check it out
0
 
krupiniAuthor Commented:
Hey man that is cool. My respects to you. However i still get the error.This is what I'm doing

one class:

import java.net.*;
import java.io.*;
public class Servers
{
         public Servers()
         {
         }
         public void writeToFileViaFtp() {
          try {
               URL ftp = new URL("ftp://try:trytry@69.194.83.97/somefiles.txt");
               URLConnection conn = ftp.openConnection();
               conn.setDoOutput(true);
               PrintWriter out = new PrintWriter(conn.getOutputStream());
               out.println("Line 1");
               out.println("Line 2");
               out.close();
          }
          catch (Exception e) {
               e.printStackTrace();
          }
          }
}


the other class:

public class ServerTwo
{
    public static void main(String[] args)
    {
        Servers server = new Servers();
        server.writeToFileViaFtp();
    }
}


What am i doing wrong.
Thanx
0
 
CEHJCommented:
Might be a network issue. Can you connect with any other ftp client from the same place as you're running the java to the same ftp server?
0
 
objectsCommented:
what error are you getting exactly?
0
 
objectsCommented:
Are you going to need to be doing more than just write a file to the ftp server?
0
 
krupiniAuthor Commented:
It is still not working but anyways I understand you've done enough, thanx
0
 
krupiniAuthor Commented:
hey, CEHJ. Have you got any ideas why i get that error?
0
 
CEHJCommented:
Did you test with another client?
0
 
mightyoneCommented:
and what error do you get?
0
 
objectsCommented:
its ok, the problem has been fixed.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 6
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now