LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-13-2009, 05:04 AM   #1
vijaykb
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Rep: Reputation: 0
Not able to create file in ftp serevr(vsftpd)


Hi,

I have set up up vsftpd server and trying to write a file into ftp server using java ftp client code. But I see some error while writing the file

FtpBean: Send command "STOR testfile.out"
line respone=553 Could not create file.
FtpBean: Released by thread.
failed to read/write into ftp serverftp.FtpException: 553 Could not create file.
ftp.FtpException: 553 Could not create file.
at ftp.FtpBean.getRespond(FtpBean.java:1395)
at ftp.FtpBean.ftpCommand(FtpBean.java:1447)
at ftp.FtpBean.getDataSocket(FtpBean.java:1568)
at ftp.FtpBean.putFile(FtpBean.java:1527)
at ftp.FtpBean.putBinaryFile(FtpBean.java:833)
at ftp.FtpBean.putBinaryFile(FtpBean.java:812)
at FtpExample.main(FtpExample.java:148)

I saw the error code 553 in document which says illegal file name. I am able to retrieve the file and put file using ftp, but not through programming API.

Please let me know what could be issue.
 
Old 03-13-2009, 05:23 AM   #2
hedgy102
Member
 
Registered: Mar 2009
Distribution: Debian,Centos
Posts: 30

Rep: Reputation: 16
Can you post your source here?
 
Old 03-13-2009, 05:37 AM   #3
vijaykb
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Original Poster
Rep: Reputation: 0
import java.io.File;
import java.io.IOException;
import java.util.Date;


import ftp.*;

/**
* This is a example of using FtpBean.
* It connects to a ftp server. Go to a directory.
* Then list its content with help of the FtpListResult class.
* Finally, it gets a binary file. In the downloading
* progress, it tells how many bytes are being downloaded.
*
* Note that this class implements the FtpObserver interface, which
* make this class have the ability to monitor the downloading or
* uploading progress. If you don't need to monitor it, then you
* don't need to implement this interface.
*
* For using more function of this FtpBean, please see the documentation.
*/
class FtpExample implements FtpObserver
{
static FtpBean ftp;
long num_of_bytes = 0;

public FtpExample()
{
// Create a new FtpBean object.
ftp = new FtpBean();
}

// Connect to a ftp server.
public void connect()
{
try
{
ftp.ftpConnect("localhost", "vijay", "hello");
ftp.setSocketTimeout(1000);
} catch(Exception e)
{
System.out.println(e);
}
}

// Close connection
public void close()
{
try
{
ftp.close();
} catch(Exception e)
{
System.out.println(e);
}
}

// Go to directory pub and list its content.
public void listDirectory()
{
FtpListResult ftplrs = null;

try
{
// Go to directory 'pub/redhat/redhat-6.2/i386/RedHat/RPMS'.
ftp.setDirectory("_cms/");
// Get its directory content.
ftplrs = ftp.getDirectoryContent();
} catch(Exception e)
{
System.out.println(e);
}

// Print out the type and file name of each row.
while(ftplrs.next())
{
int type = ftplrs.getType();
if(type == FtpListResult.DIRECTORY)
System.out.print("DIR\t");
else if(type == FtpListResult.FILE)
System.out.print("FILE\t");
else if(type == FtpListResult.LINK)
System.out.print("LINK\t");
else if(type == FtpListResult.OTHERS)
System.out.print("OTHER\t");
System.out.println(ftplrs.getName());
}
}

// Get the file.
public void getFile()
{
try
{
// Get the binary file 'kernel-2.2.14-5.0.i386.rpm' and save it to
// the name 'local_file_name' in the hard disk.
// Passing this class which implements the FtpObserver interface to
// monitor this downloading progress. Every time new bytes are read,
// the byteRead(int) method of this class is invoked by the bean.
ftp.getBinaryFile("build.txt", "local_file_name", this);
} catch(Exception e)
{
System.out.println(e);
}
}

// Implemented for FtpObserver interface.
// To monitor download progress.
public void byteRead(int bytes)
{
num_of_bytes += bytes;
System.out.println(num_of_bytes + " of bytes read already.");
}

// Needed to implements by FtpObserver interface.
public void byteWrite(int bytes)
{
}


// Main
public static void main(String[] args)
{
FtpExample example = new FtpExample();
example.connect();
example.listDirectory();
//example.getFile();

Date d = new Date();
long t = d.getTime();
System.out.println("test file " + t);

File f = new File("/home/vijay");
/*if ((! f.exists())||(! f.isDirectory())) {
System.out.println("invalid ftpdir " );
return ;
}*/

File cms = new File(f, CM_DIR);
if (f.exists()&&(! f.isDirectory())) {
System.out.println("invalid cmsdir " );
return ;
}

cms.mkdir();

try {
ftp.putBinaryFile("testfile.out", TEST_DATA);
/*
byte[] ret = ftp.getBinaryFile(Long.toString(t));
int i = 0;
for (i=0;i<TEST_DATA.length; i++) {
if (ret[i] != TEST_DATA[i]) {
throw new IOException("read error " + i);
}
}*/
} catch (Exception e) {
System.out.println("failed to read/write into ftp server" + e);
e.printStackTrace();
return ;
}

File tmp = new File(cms, Long.toString(t));
if (! tmp.exists()) {
System.out.println("failed test file in cms dir " + tmp.getAbsolutePath());
return ;
}
tmp.delete();

try {
ftp.close();
} catch (Exception e) {
System.out.println("failed to exit ftp session " + e);
}

//return ClientValidationResult.SUCCESS;
example.getFile();
example.close();
}
private static byte[] TEST_DATA = {50, 51, 52, 53, 54, 55, 56, 57, 58, 59};
public static final String CM_DIR = "/_cm/";
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vsftpd Error 553 - Could not create file KimInWis Fedora 14 10-09-2013 11:43 AM
'553 Could not create file' in vsftpd FTP Server on CentOS 5 Fabian10 Linux - Server 2 11-26-2007 11:13 AM
How to create a ftp user on VSFTPD in linux rahiljavaid Linux - Newbie 2 11-08-2006 11:42 AM
create ftp user for vsftpd server without home directory cccc Linux - Networking 2 07-30-2005 06:32 AM
ok i giv eup on samba, i want to create an ftp share now...vsftpd rvn Linux - Newbie 3 10-10-2003 01:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration