• Post Reply Bookmark Topic Watch Topic
  • New Topic

FtpClient  RSS feed

 
Craig Dumolien
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below I have a snipit of code which is supposed to place the file "test_transfer.txt" on the specified host. However, I am getting the following error and I don't know why. I can transfer the file, without problems, through a regular FTP program.

If anyone can point out what I am not seeing please do so. Also, I am required to use the FtpClient Class.


java.io.FileNotFoundException: STOR /path/test_transfer.txt: 550 permission denied



FtpClient client = null;
String dirPathLocal = "C:";
try {
String host = "ftp.server.com";
String username = "username";
String password = "password";

//set FtpClient object
client = new FtpClient(host);
client.login(username, password);
client.binary();

//put file on server
String testTransferFileName = "C:\test_transfer.txt";
client.put(testTransferFileName);
}
catch (...) {...}
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure why this would cause the error you are seeing, butproduces a String that contains "C", ":", tab character, "e", "s" and so on. That's because "\t" is the Java escape for the tab character. What you want is to escape the backslash so it comes out as itself:
 
Craig Dumolien
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem I was having was that the FtpClient.put method returns an OutputStream, which I was doing nothing with.

Below is the code where I'm actually working with that OutputStream. However, now the file is getting created on the server, but the text inside the file is not getting transfered.

Any ideas? Thanks.


osTestTransfer = client.put("test_transfer.txt");
bosTestTransfer = new BufferedOutputStream(osTestTransfer);

if (testTransferFile.exists()) {
isTestTransfer = new FileInputStream(testTransferFile);
bisTestTransfer = new BufferedInputStream(isTestTransfer);

int bytesRead1 = 0;
while ( (bytesRead1 = bisTestTransfer.read(buffer)) > 0 ) {
bosTestTransfer.write(buffer,0,bytesRead1);
}
}
 
Craig Dumolien
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured that one out. I needed to do a bosTestTransfer.flush(); when the while statement finished.

The reason nothing showed up is that I was using an file with less than 4096 bytes.

Thanks for the help.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!