Ftp file transfer in Java
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); } } }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement