Solved

writing to an ftp server

Posted on 2004-04-27
18
801 Views
Last Modified: 2007-12-19
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
Comment
Question by:krupini
  • 7
  • 6
  • 3
  • +1
18 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10931819
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
 

Author Comment

by:krupini
ID: 10933712
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 10933775
That would probably be a username/password thing - code works fine for me
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 86

Expert Comment

by:CEHJ
ID: 10933783
(of course, you have to put *your* username and password in the url ;-))
0
 
LVL 6

Expert Comment

by:mightyone
ID: 10933826
;-)
0
 

Author Comment

by:krupini
ID: 10933922
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
 

Author Comment

by:krupini
ID: 10933924
Aprreciate you help
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10933963
Oh sorry - missed the last bit. Just wrote a file up there called somefile.txt. Shall write to the other
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10933967
OK - check it out
0
 

Author Comment

by:krupini
ID: 10934070
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 10934091
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
 
LVL 92

Expert Comment

by:objects
ID: 10934099
what error are you getting exactly?
0
 
LVL 92

Expert Comment

by:objects
ID: 10934103
Are you going to need to be doing more than just write a file to the ftp server?
0
 

Author Comment

by:krupini
ID: 10934228
It is still not working but anyways I understand you've done enough, thanx
0
 

Author Comment

by:krupini
ID: 10934851
hey, CEHJ. Have you got any ideas why i get that error?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10937215
Did you test with another client?
0
 
LVL 6

Expert Comment

by:mightyone
ID: 10941646
and what error do you get?
0
 
LVL 92

Expert Comment

by:objects
ID: 10944225
its ok, the problem has been fixed.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 104
replace a word with other 1 45
hibernate insert example 13 34
hashmap order 17 36
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question