Skip to main content
gamedev.net
🔒 Locked

Ftp file transfer in Java

Started by j14rk1n Dec 10, 2005 at 4:39 PM 0 replies 1.5k views
Original Post
j14rk1n
j14rk1n
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); } } }
hplus0603
hplus0603
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 };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.