I solved the issue by going through the source code. I noticed that the
libraries were sending a "MODE" command ot the server, and if you notice
below, I wasn't checking the return type of the changeWorkingDirectory
call - it was failing because setting the MODE to binary is not correct.
I should have been calling setFileType.
David.
David Griffiths wrote:
I'm new to the commons-net library, but I've read through the FAQ and
the APIs. I've also googled my problem.
I'm downloading images from a site using the commons-HttpClient,
resizing them, and then ftp'ing them up to an image server, but the
images appear to be corrupt (can't view them in a browser on the
server they've been uploaded to, ditto if I scp them down).
I am setting the file-transfer-type to binary when I create the
connection:
ftpConnections[iServerCount].setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
ftpConnections[iServerCount].completePendingCommand();
I've tried various things to fix this.
Attempt #1:
Handing a stream over to the FTPClient to upload the image
FileInputStream fInputStream = null;
fInputStream = new FileInputStream(f);
ftpConnections[iServerCount].changeWorkingDirectory(strRemoteDirectory);
ftpConnections[iServerCount].setFileTransferMode(FTP.BINARY_FILE_TYPE);
ftpConnections[iServerCount].completePendingCommand();
if ( ftpConnections[iServerCount].storeFile(f.getName(),
fInputStream) ) bOneSucceeded = true;
Attempt #2
Using two streams to upload the image
fInputStream = new FileInputStream(f);
ftpConnections[iServerCount].changeWorkingDirectory(strRemoteDirectory);
ftpConnections[iServerCount].setFileTransferMode(FTP.BINARY_FILE_TYPE);
ftpConnections[iServerCount].completePendingCommand();
OutputStream os =
ftpConnections[iServerCount].storeFileStream(f.getName());
byte[] bData = new byte[2048];
while(true)
{
int iBytesRead = fInputStream.read(bData);
if (iBytesRead == -1) break;
os.write(bData, 0, iBytesRead);
}
os.flush();
os.close();
fInputStream.close();
ftpConnections[iServerCount].completePendingCommand();
I get a successful status back in both cases.
I've checked that the images I am downloading are fine and processing
are fine (the images I am ftp'ing up are fine). I've also tried using
a DataInputStream instead of a FileInputStream.
I've also tried using the FTP.IMAGE_FILE_TYPE to see if that would
make a difference.
Any insight would be appreciated.
David
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]