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
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