![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| FtpProtocolException: PORT :500 While my FTP upload class is attempting to upload a file, it breaks and get this error Quote:
My class is the following Code: class FileUpload
{
/**
* Upload a file to a FTP server. A FTP URL is generated with the
* following syntax:
* ftp://user:password@host:port/filePath;type=i.
*
* @param ftpServer , FTP server address (optional port ':portNumber').
* @param user , Optional user name to login.
* @param password , Optional password for user.
* @param fileName , Destination file name on FTP server (with optional
* preceding relative path, e.g. "myDir/myFile.txt").
* @param source , Source file to upload.
* @throws MalformedURLException, IOException on error.
*/
public void upload( String ftpServer, String user, String password, String fileName, File source )
throws MalformedURLException,
IOException
{
if (ftpServer != null && fileName != null && source != null)
{
StringBuffer sb = new StringBuffer( "ftp://" );
// check for authentication else assume its anonymous access.
if (user != null && password != null)
{
sb.append( user );
sb.append( ':' );
sb.append( password );
sb.append( '@' );
}
sb.append( ftpServer );
sb.append( '/' );
sb.append( fileName );
/*
* type ==> a=ASCII mode, i=image (binary) mode, d= file directory
* listing
*/
sb.append( ";type=a" );
System.out.println(sb);
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try
{
URL url = new URL( sb.toString() );
URLConnection urlc = url.openConnection();
bos = new BufferedOutputStream( urlc.getOutputStream() );
bis = new BufferedInputStream( new FileInputStream( source ) );
int i;
// read byte by byte until end of stream
while ((i = bis.read()) != -1)
{
bos.write( i );
}
}
finally
{
if (bis != null)
{
try
{
bis.close();
}
catch (IOException e)
{
bis = null;
}
}
if (bos != null)
{
try
{
bos.close();
}
catch (IOException e)
{
bos = null;
}
}
}
}
else
{
System.out.println( "Input not available." );
}
}
} So does any body got an idea why i get this error from time to time? Last edited by zaher1988 : 11-14-2007 at 04:11 AM. |
| |
| |||
| There is a specific protocol associated with FTP. There are variations possible with that protocol. Quite a few actually. Even within that protocol there can be variations based on exactly which commands a specific ftp server expects. In general purpose ftp clients this is handle by providing varying options. sun.net.www.protocol.ftp doesn't implement all of the possibilities. It is possible that it only implements one. So it either works or it doesn't. If it doesn't then you need to try another solution. Such as the jakarta commons net solution. Even with that you still might need to experiment with a particular server. Edit: Java Programming - FtpProtocolException: PORT :500 JavaWorld Forums: error in ftp code Socket Programming - problem with sun.net.ftp __________________ Day Cares | Golf Courses | Disc Golf Courses | Campgrounds | Ice Rinks | Paintball Fields | Dentists | Plastic Surgeons | Aging Jokes Catholic Churches | Lutheran Churches | Methodist Churches | Episcopal Churches | Clean Jokes Last edited by Lee : 11-14-2007 at 02:37 PM. Reason: Edit your last post! |
| |||
| Thank you for your replies. Actually i passed over the suggested links before and i got this same reply on a thread i posted on Java Programming forums which you have also included in your links post. Anyway let's focus on switching to passive mode rather than active. How can my class use passive mode? what should we change in it? |
| |||
| __________________ Day Cares | Golf Courses | Disc Golf Courses | Campgrounds | Ice Rinks | Paintball Fields | Dentists | Plastic Surgeons | Aging Jokes Catholic Churches | Lutheran Churches | Methodist Churches | Episcopal Churches | Clean Jokes |
| |||
| Quote: I have read about FtpBean before, never thought of trying it, anyway what i did now is a mix between my class and FtpBean, so that when any fails the program will try the other method, and it works!. Thank you for your cooperation. |
| |||
| Good work buddy ![]() __________________ Day Cares | Golf Courses | Disc Golf Courses | Campgrounds | Ice Rinks | Paintball Fields | Dentists | Plastic Surgeons | Aging Jokes Catholic Churches | Lutheran Churches | Methodist Churches | Episcopal Churches | Clean Jokes |
![]() |
| Thread Tools | |
| Display Modes | |
| |