Advertisement

Ftp file transfer in Java

Started by December 10, 2005 04:39 PM
0 comments, last by hplus0603 19 years, 2 months ago
I've connected and logged into the ftp server. I use an FtpClient (http://swig.stanford.edu/pub/java/javadoc/sun/net/ftp/FtpClient.html) object to connect and login. What I want to do is upload a file that I have onto the server. When I tell the program to put the file onto the server (client.put(filename);), it does what it's told, but there's no contents in the file. All there is is a file with the name I gave it, but there's nothing in the file. By the way, client.put() returns a TelnetOutputStream. I'm so confused. Someone please help before I go crazy. Here's my code now: import javax.swing.*; import java.awt.*; import sun.net.ftp.*; public class FTPUpload { private FtpClient client = null; public static void main(String [] args) { FTPUpload app = new FTPUpload("ftp.blank.com", "username", "password"); app.uploadFile("text.txt"); } public FTPUpload(String url, String username, String password) { try { client = new FtpClient(url); client.login(username, password); } catch(java.io.IOException e) { System.out.println("Connection Problem: " + e); } } public void uploadFile(String filename) { try { client.put(filename); <- I think this might be the problem... } catch(java.io.IOException e) { System.out.println("File Upload error: " + e); } } }
Here's my guess: If it returns a telnet output stream, then that's the stream you have to write the contents of the file to. The filename argument for "put" is likely just what you want the file to be called on the server.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement