Reputation: 31
I am trying to make a function in Java :
public static void upload_files(String us, String pw, String ip, String f){
try
{
FTPClient client = new FTPClient();
client.connect(ip);
client.login(us,pw);
client.upload(f);
} catch(Exception e) {
e.printStackTrace();
}
}
I added apache libraries, but sadly I got an error on "upload" line I suppose I do not use correctly the method upload, but I don't know how to.
When I compile it with Netbeans, it is noticing me that there is an error line "client.upload(f);"
The error given in output is "java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: org.apache.commons.net.ftp.FTPClient.upload"
Thank you all in advance. nb : "f" is the direct path to my file
EDIT :
The problem is "quite" solved since now I upload some files on my ftp server BUT sadly they are all empty, as noticed on below.
Upvotes: 0
Views: 3871
Reputation: 8245
The Apache FTPClient does not have an upload
method.
What it does have, is a method called storeFile .
It takes as it's parameters the name the file should have on the server, and an InputStream
. The InputStream reads from your local file, so you need:
InputStream is = new FileInputStream( f );
client.storeFile( some_name, is );
Upvotes: 2