Reputation: 41
I've been trying to send a file to an ftp server via an FTPClient but when I get the reply string it says:
553 Can't open file: No such file or directory.
Here is the code:
try
{
FTPClient client = new FTPClient();
client.connect(hostname);
client.login(username, password);
client.setFileType(FTP.BINARY_FILE_TYPE);
client.enterLocalPassiveMode();
client.changeWorkingDirectory(workingDir);
File dir = new File(savePath + fileName);
FileInputStream fIS = new FileInputStream(dir);
for(File files : dir.listFiles())
{
boolean success = client.storeFile(files.getPath(), fIS);
Toast.makeText(getBaseContext(), client.getReplyString(), Toast.LENGTH_LONG).show();
Toast.makeText(getBaseContext(), files.getPath() + " Stored = " + success, Toast.LENGTH_LONG).show();
}
fIS.close();
client.logout();
}
catch (SocketException e)
{
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
catch (IOException e)
{
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
I've been looking all over the internet for answers but nothing has worked.
Upvotes: 1
Views: 5143
Reputation: 41
I fixed the problem with help from CoolBeans.
For anyone with similar problem the solution is
1.Change the:
client.storeFile(files.getPath(), fIS);
to:
client.storeFile(files.getName(), fIS);
And move the FileInputStream into the for-loop and change it to:
new FileInputStream(files);
Upvotes: 1