You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "geek.shrek" <mi...@yahoo.com> on 2009/09/25 01:44:33 UTC

Failed creating file using VFS FTP

Hi,

I'm trying to create a file using VFS FTP but it said the file already exist eventhough it's not exists

Could not create folder "ftp://myuser:mypass@123.345.678.890/" because it already exists and is a file

Here's my code.

        try
        {
   
            FileObject fo = fsManager.resolveFile("ftp://myuser:mypass@123.345.678.890", authenticate());
            FileObject f = fo.resolveFile("/mynewfolder/myfile.txt");
            System.out.println("f " + f.exists());  --> return false;
            f.createFile();
            
            System.out.println("Is readable: " + f.exists());
            
            System.out.println("Last Modified" + f.getContent().getLastModifiedTime());
        }
        catch (FileSystemException e)
        {
            e.printStackTrace();
        }

private FileSystemOptions authenticate()
    {
        StaticUserAuthenticator auth = new StaticUserAuthenticator(null, this.username, this.password);
        FileSystemOptions opts = new FileSystemOptions();
        try
        {
            DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
        }
        catch (FileSystemException e1)
        {
            e1.printStackTrace();
        }
        return opts;
    }

Could someone please point me how can I create file using VFS?

Thanks,



      __________________________________________________________________________________
Get more done like never before with Yahoo!7 Mail.
Learn more: http://au.overview.mail.yahoo.com/

Re: [Bulk] Failed creating file using VFS FTP

Posted by Ernesto De Santis <ed...@yahoo.com.ar>.
Hi Geek (!)

I tried to use your example in my local file system, and ti doesn't work.
I just change the path of the new path, cutting off the first "/" and it 
works.

 > FileObject f = fo.resolveFile("mynewfolder/myfile.txt");

Try that and good luck,
Ernesto.


geek.shrek escribió:
> Hi,
>
> I'm trying to create a file using VFS FTP but it said the file already exist eventhough it's not exists
>
> Could not create folder "ftp://myuser:mypass@123.345.678.890/" because it already exists and is a file
>
> Here's my code.
>
>         try
>         {
>    
>             FileObject fo = fsManager.resolveFile("ftp://myuser:mypass@123.345.678.890", authenticate());
>             FileObject f = fo.resolveFile("/mynewfolder/myfile.txt");
>             System.out.println("f " + f.exists());  --> return false;
>             f.createFile();
>             
>             System.out.println("Is readable: " + f.exists());
>             
>             System.out.println("Last Modified" + f.getContent().getLastModifiedTime());
>         }
>         catch (FileSystemException e)
>         {
>             e.printStackTrace();
>         }
>
> private FileSystemOptions authenticate()
>     {
>         StaticUserAuthenticator auth = new StaticUserAuthenticator(null, this.username, this.password);
>         FileSystemOptions opts = new FileSystemOptions();
>         try
>         {
>             DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
>         }
>         catch (FileSystemException e1)
>         {
>             e1.printStackTrace();
>         }
>         return opts;
>     }
>
> Could someone please point me how can I create file using VFS?
>
> Thanks,
>
>
>
>       __________________________________________________________________________________
> Get more done like never before with Yahoo!7 Mail.
> Learn more: http://au.overview.mail.yahoo.com/
>