aspose file tools
The moose likes Other JSE/JEE APIs and the fly likes FtpClient Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply Bookmark "FtpClient" Watch "FtpClient" New topic
Author

FtpClient

Craig Dumolien
Greenhorn

Joined: Nov 07, 2005
Posts: 20
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
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

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

Joined: Nov 07, 2005
Posts: 20
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

Joined: Nov 07, 2005
Posts: 20
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: FtpClient
 
Similar Threads
FTP downloading issues
Reading log files from various unix servers through Java program on windows
Code to dowload Ftp FILE from ftp server (cross platform)
using FTP view client machine files
FTP upload