Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jakarta Commons Net - FTPClient Assistance

Status
Not open for further replies.

plotzer

Programmer
Aug 28, 2001
35
0
0
US
I am building a little app to generate a PNG image and then ftp it to another webserver. I am using the jakarta commons Net FTPClient for the ftp portion. I am able to send the file to the server, but the image cannot display because it "contains errors". Somehow in the transfer process the image is being corrupted. The file sizes appear to be the same. My ftp code is as follows:


try
{
String host = "myserver.com";
String path = "/data/ String username = "user";
String password = "password";

FTPClient ftp = new FTPClient();
ftp.connect(host);
ftp.login( username, password );
System.out.println("Connected to " + host + ".");
System.out.print(ftp.getReplyString());

ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.setFileTransferMode(FTP.BINARY_FILE_TYPE);
ftp.changeWorkingDirectory(path);
File file = new File( mapName);
FileInputStream fis = new FileInputStream( file );
if (ftp.storeFile(mapName,fis))
{
System.out.print("File Sent: " + ftp.getReplyString());
}
else{
System.out.print("File Not Sent: " + ftp.getReplyString());
}
fis.close();


// Logout from the FTP Server and disconnect
ftp.logout();
ftp.disconnect();
}
catch( Exception e )
{
e.printStackTrace();
}



I've actually tried a few different file types and transfer modes (IMAGE_FILE_TYPE, etc), but I keep getting the same result.

Let me know what you think. Thanks in advance
 
Ignore this message. I figured out what I was doing wrong. Thanks
 
A good practice is tell the other people how do you solve your problems so other can use the knowledge to solve their own problems.

Cheers,

Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top