Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
10.6k views
in Java FTP by (320 points)
ERROR [FTPClient] 4 Nov 2009 14:22:36.734 : Caught and rethrowing exception in initPut() : C:\temp\file.txt: The filename, directory name, or volume label syntax is incorrect

I am getting this error when giving the path along with the filename. When filename alone is given, it is taken from the current directory(working dir) of the local system. But I need to put it in another folder in the same local system and then transfer the files to the remote ftp server. The local folder will have a number of files, which are to be transferred.

How do I specify the file path? This is my code

String filename="C:\\temp\\file.txt";
FileTransferClient ftp = null;
try {
            // create client
            log.info("Creating FTP client");
            ftp = new FileTransferClient();

            // set remote host
            ftp.setRemoteHost(host);
            ftp.setUserName(username);
            ftp.setPassword(password);

            // connect to the server
            log.info("Connecting to server " + host);
            ftp.connect();
            log.info("Connected and logged in to server " + host);

            log.info("Uploading file");
            ftp.uploadFile(filename, filename);
            log.info("File uploaded");
            
            ftp.disconnect();
}
catch (Exception e)
{
                  e.printStackTrace();
}

8 Answers

0 votes
by (162k points)
It depends - but you certainly can't use C:\\temp for the remote file system.

You'll need to log in with ftp.exe and work out where the file should go. You may need to create a destination directory on the remote file system.
0 votes
by (320 points)
I am not talking about the remote directory. I am talking about local directory, where the files to be uploaded to ftp are kept. I am not able to refer to those files using the above code.
C:\temp\ is the directory in my system and the ftp server is in LAN. I am not able to refer the file in my system using full path C:\temp\file.txt.
That is my problem. Please help.
0 votes
by (162k points)
So C:\temp\file.txt exists and your app has permission to access that file?
0 votes
by (320 points)
Yes it does exist and there is permission to read the file.

I tried to call the file by calling relative path like this (for this the file was copied to parent directory of my working directory)
String filename="../file.txt";

it worked.

But when I am giving folder name like this (for this the file was copied to child directory named "folder" of my working directory)
String filename="./folder/file.txt";

it is not working.

When just the file name is given like this
String filename="file.txt";

it is working and is taking from the working directory.

Why is it so?
Is there any restriction in giving folder names?
Is it not possible to give full filepath for a file?

Can you please give me a full example where you have referred the file with its full filepath? I think that will help
0 votes
by (162k points)
Please post the log file at the DEBUG level.
0 votes
by (320 points)
This the working code


/*
 * 
 * Copyright (C) 2006 Enterprise Distributed Technologies Ltd
 * 
 * www.enterprisedt.com
 */

import com.enterprisedt.net.ftp.FileTransferClient;
import com.enterprisedt.util.debug.Level;
import com.enterprisedt.util.debug.Logger;
import java.io.File;

public class UploadDownloadFiles {

    public static void main(String[] args) {

        // we want remote host, user name and password
        if (args.length < 3) {
            System.out
                    .println("Usage: run remote-host username password");
            System.exit(1);
        }

        // extract command-line arguments
        String host = args[0];
        String username = args[1];
        String password = args[2];
///    String filename = "UploadDownloadFiles.java";
   String filename="file.txt";

File filepath=new File(filename);
System.out.println("FilePath:"+filepath.getAbsolutePath());

        // set up logger so that we get some output
        Logger log = Logger.getLogger(UploadDownloadFiles.class);
        Logger.setLevel(Level.INFO);

        FileTransferClient ftp = null;

        try {
            // create client
            log.info("Creating FTP client");
            ftp = new FileTransferClient();

            // set remote host
            ftp.setRemoteHost(host);
            ftp.setUserName(username);
            ftp.setPassword(password);

            // connect to the server
            log.info("Connecting to server " + host);
            ftp.connect();
            log.info("Connected and logged in to server " + host);

            log.info("Uploading file");
            ftp.uploadFile(filename, filename);
            log.info("File uploaded");

            // Shut down client
            log.info("Quitting client");
            ftp.disconnect();

            log.info("Example complete");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}



And this is its debug
FilePath:C:\Documents and Settings\<user>\Desktop\edtftpj\edtftpj-2.0.5\examples\howto\upload_download_and_delete_a_file\file.txt
INFO [UploadDownloadFiles] 5 Nov 2009 14:34:07.937 : Creating FTP client
INFO [UploadDownloadFiles] 5 Nov 2009 14:34:07.984 : Connecting to server localhost
INFO [UploadDownloadFiles] 5 Nov 2009 14:34:08.031 : Connected and logged in to server localhost
INFO [UploadDownloadFiles] 5 Nov 2009 14:34:08.046 : Uploading file
INFO [UploadDownloadFiles] 5 Nov 2009 14:34:08.046 : File uploaded
INFO [UploadDownloadFiles] 5 Nov 2009 14:34:08.062 : Quitting client
INFO [UploadDownloadFiles] 5 Nov 2009 14:34:08.062 : Example complete


This worked because the file is in the current directory as you can see.

Now the problem case:
Assign filename with full path
String filename="c:\\temp\\file.txt";


Its debug:
FilePath:c:\temp\file.txt
INFO [UploadDownloadFiles] 5 Nov 2009 14:37:18.093 : Creating FTP client
INFO [UploadDownloadFiles] 5 Nov 2009 14:37:18.140 : Connecting to server localhost
INFO [UploadDownloadFiles] 5 Nov 2009 14:37:18.187 : Connected and logged in to server localhost
INFO [UploadDownloadFiles] 5 Nov 2009 14:37:18.187 : Uploading file
INFO [FTPControlSocket] 5 Nov 2009 14:37:18.203 : Expected reply codes = [125,150,151,350]
ERROR [FTPClient] 5 Nov 2009 14:37:18.203 : Caught and rethrowing exception in initPut() : c:\temp\file.txt: The filename, directory name, or volume label syntax is incorrect.
com.enterprisedt.net.ftp.FTPException: 550 c:\temp\file.txt: The filename, directory name, or volume label syntax is incorrect.
at com.enterprisedt.net.ftp.FTPControlSocket.validateReply(FTPControlSocket.java:1179)
at com.enterprisedt.net.ftp.FTPClient.initPut(FTPClient.java:2630)
at com.enterprisedt.net.ftp.FTPClient.putData(FTPClient.java:2689)
at com.enterprisedt.net.ftp.FTPClient.putStream(FTPClient.java:2428)
at com.enterprisedt.net.ftp.FTPClient.put(FTPClient.java:2396)
at com.enterprisedt.net.ftp.FileTransferClient.uploadFile(FileTransferClient.java:785)
at com.enterprisedt.net.ftp.FileTransferClient.uploadFile(FileTransferClient.java:759)
at UploadDownloadFiles.main(UploadDownloadFiles.java:56)


com.enterprisedt.net.ftp.FTPException: 550 c:\temp\file.txt: The filename, directory name, or volume label syntax is incorrect.
at com.enterprisedt.net.ftp.FTPControlSocket.validateReply(FTPControlSocket.java:1179)
at com.enterprisedt.net.ftp.FTPClient.initPut(FTPClient.java:2630)
at com.enterprisedt.net.ftp.FTPClient.putData(FTPClient.java:2689)
at com.enterprisedt.net.ftp.FTPClient.putStream(FTPClient.java:2428)
at com.enterprisedt.net.ftp.FTPClient.put(FTPClient.java:2396)
at com.enterprisedt.net.ftp.FileTransferClient.uploadFile(FileTransferClient.java:785)
at com.enterprisedt.net.ftp.FileTransferClient.uploadFile(FileTransferClient.java:759)
at UploadDownloadFiles.main(UploadDownloadFiles.java:56)
com.enterprisedt.net.ftp.FTPException: 550 c:\temp\file.txt: The filename, directory name, or volume label syntax is incorrect.
at com.enterprisedt.net.ftp.FTPControlSocket.validateReply(FTPControlSocket.java:1179)
at com.enterprisedt.net.ftp.FTPClient.initPut(FTPClient.java:2630)
at com.enterprisedt.net.ftp.FTPClient.putData(FTPClient.java:2689)
at com.enterprisedt.net.ftp.FTPClient.putStream(FTPClient.java:2428)
at com.enterprisedt.net.ftp.FTPClient.put(FTPClient.java:2396)
at com.enterprisedt.net.ftp.FileTransferClient.uploadFile(FileTransferClient.java:785)
at com.enterprisedt.net.ftp.FileTransferClient.uploadFile(FileTransferClient.java:759)
at UploadDownloadFiles.main(UploadDownloadFiles.java:56)


Then I tried this also
String filename="/temp/file.txt";

Its Debug
FilePath:C:\temp\file.txt
INFO [UploadDownloadFiles] 5 Nov 2009 14:40:16.187 : Creating FTP client
INFO [UploadDownloadFiles] 5 Nov 2009 14:40:16.234 : Connecting to server localhost
INFO [UploadDownloadFiles] 5 Nov 2009 14:40:16.281 : Connected and logged in to server localhost
0 votes
by (162k points)
Ok, as I said at the very beginning, you can't use C:\\temp for the remote file system. That's the problem.

You have to do something like:

ftp.uploadFile("C:\\temp\\file.txt", "file.txt");

This will put file.txt in the current working directory on the remote server.

If you want it elsewhere, login in via ftp.exe and figure out where you want it. Type 'pwd' to find the path of that location.
0 votes
by (320 points)
Sorry pal, my eyes was closed. I didn't really see what you said. Now I understood. Silly mistake.. damn

I gave the filename like this
String filename="D:\\file.txt";

and then called
ftp.upload(filename,filename);

hmm...

it should be done like this

String filename="file.txt";
String localfilepath="D:\\file.txt";
ftp.upload(localfilepath,filename);


damn.. why dint i notice this.. :x

Thanks a lot Bruce. Thanks a lot.

Categories

...