• Post Reply Bookmark Topic Watch Topic
  • New Topic

FTP w/ Java  RSS feed

 
Bill White
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have been trying to use Saverse's FTP API to FTP images to a server. This works GREAT with text files but, the images come back corrupted.
Here is my code:
public boolean sendFile(String localURL, String remoteFileName)
{
boolean success = false;
try
{
InputStream is = new java.io.FileInputStream(localURL);

success = changeToWorkingDirectory();

aClient.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);

System.out.println(aClient.getReplyString());

if(success)
{

success = aClient.storeFile(remoteFileName, is);
is.close();
}
}
catch(java.io.FileNotFoundException e)
{
System.out.println("File " + localURL + " not found.");
e.printStackTrace();
}
catch(java.io.IOException e)
{
System.out.println("IOException in SWMediaFTPBean.sendFile()");
e.printStackTrace();
}
finally
{
return success;
}
}
The output from the sys-out is:
501 'MODE I' unrecognized transfer mode.
The file does get FTP'ed over, but it comes back corrupt.
 
Neal Swearer
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Find the correct way to set the transfer mode to binary.
 
Bill White
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, that is what I figured. However the DOCs say that binary transfer mode is the default. So, that is what I tried first. Still a no go.
Thanks though.
 
Marilyn de Queiroz
Sheriff
Posts: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neal S
Hi,

Welcome to JavaRanch! Please adjust your display name to meet the JavaRanch Naming Policy. A last initial does not conform to the policy.

You can change it here.

Thanks!
 
Bill White
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OMG Neal, you know what? I tried to show my name but your account creation code would not allow Bill May or William May.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps both of those names are already taken. You could use Bill May Jr. instead. This would seem to be in the spirit of the naming rules here at Java Ranch. Of course, I'm only a participant here, so take my advice for a grain of salt.
Regards,
Layne
 
Marilyn de Queiroz
Sheriff
Posts: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds good to me, Layne.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!