www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] FTP file upload

  1. #1
    Join Date
    May 2007
    Location
    Sweden
    Posts
    123

    resolved [RESOLVED] FTP file upload

    Hey

    I've googled "Java FTP" and found a several easy FTP classes for uploading files. The problem is that they don't work. When I use FTPConnection.java (uploaded below), I can connect and log in but not upload a file. I've tried to set debug-mode on, and everything seems to be ok. I see a welcome message from the server host, that my username and password is valid and how much space I've used. The only error message I get before I'm trying to transfer the file, is:
    Code:
    Could not set transfer type
    200 TYPE is now 8-bit binary
    200 PORT command successful
    200 TYPE is now 8-bit binary
    Does anyone know what this means/how to fix it or can show me another easy FTP class that works?

    Thanks for your help!
    //Totte
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    Can you try the URL based FTP? Like this:

    Code:
    URL url = new URL("ftp://user01:pass1234@ftp.foo.com/README.txt;type=i");
    URLConnection urlc = url.openConnection();
    InputStream is = urlc.getInputStream(); // To download
    OutputStream os = urlc.getOutputStream(); // To upload
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  3. #3
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,123
    post your test code as well that you are using to upload data
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  4. #4
    Join Date
    May 2007
    Location
    Sweden
    Posts
    123
    How do I write bytes? How do I get bytes from the file?

    I've uploaded my code that I tested for uploading a file below. I use the following command to run the program:
    Code:
    java UploadTest ftp.telia.com userXXXX passXXXX test.html
    NOTE: I can log in, but it fails when the file is going to be uploaded...
    Attached Files Attached Files

  5. #5
    Join Date
    May 2007
    Location
    Sweden
    Posts
    123
    EDIT: This works correctly:
    Code:
    public static void main(String[] arg){
         String username = arg[1], password = arg[2], host = arg[0];
         try{
              URL url = new URL("ftp://"+username+":"+password+"@"+host+"/test.html");
              URLConnection urlc = url.openConnection();
              OutputStream os = urlc.getOutputStream(); // To upload
              os.write(("This is a test...").getBytes());
              os.close();
         }catch(IOException e){
              System.err.println(e);
              e.printStackTrace();
         }
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles