Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8.6k views
in Java FTP by (360 points)
Hi,

I'm writing an application which has to delete a file on a remote server. The problem, which I can't seem to solve is the following: I have the name of the file stored in a variable called fileName (type String). The name stored in the variable is correct, i checked it and compared it to the actual file name on the server and it's ok. The problem is, that if I call the client.deleteFile(fileName) method like this, it doesn't work, but if i call it this way: client.deleteFile("thename.jpg") it works. And the string and the variable are the same... I don't know what could be wrong. Everything is fine with the connection, I'm able to upload the file and it all works fine except for this... I also thought maybe the problem was that I was in the wrong directory, but it's all fine.

Here's the code snippet:

//before this i set up the connection
ftpDelete.changeDirectory("dir1"); //my directory where file is located
String fileName = "file1.jpg"; //file name
//deleting
client.deleteFile(fileName); //this doesn't work but this does: client.deleteFile("file1.jpg");
//disconnect
client.disconnect();


And here's what I get as an output in the console:
SEVERE: null
com.enterprisedt.net.ftp.FTPException: 550 2011_00000001_RACUN.jpg : The system cannot find the path specified.
at com.enterprisedt.net.ftp.FTPControlSocket.validateReply(FTPControlSocket.java:1223)
at com.enterprisedt.net.ftp.FTPClient.delete(FTPClient.java:3884)
at com.enterprisedt.net.ftp.FileTransferClient.deleteFile(FileTransferClient.java:957)
at virtcomui.VirtcomGUIOsnova.brisiNaServerju(VirtcomGUIOsnova.java:2497)
at virtcomui.VirtcomGUIOsnova.brisiIkonaActionPerformed(VirtcomGUIOsnova.java:2447)
at virtcomui.VirtcomGUIOsnova.access$1500(VirtcomGUIOsnova.java:60)
at virtcomui.VirtcomGUIOsnova$21.actionPerformed(VirtcomGUIOsnova.java:748)


please, help, because it's driving me crazy...

12 Answers

0 votes
by (162k points)
Enable logging at DEBUG level - the output will tell you what command (including filename) is being sent to the server.
0 votes
by (360 points)
so i put logging in my code, and here's what I get:

DEBUG [virtcomui.VirtcomGUIOsnova] 4 Nov 2011 19:47:51.121 : Connecting
DEBUG [FileTransferClient] 4 Nov 2011 19:47:51.122 : Configured client
DEBUG [FTPClient] 4 Nov 2011 19:47:51.123 : Connecting to /192.168.0.100:21
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.128 : 220 Microsoft FTP Service
DEBUG [FileTransferClient] 4 Nov 2011 19:47:51.128 : Client connected
DEBUG [FileTransferClient] 4 Nov 2011 19:47:51.129 : Logging in
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.129 : ---> USER viki
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.131 : 331 Password required for viki.
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.131 : ---> PASS ********
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.135 : 230 User viki logged in.
DEBUG [FileTransferClient] 4 Nov 2011 19:47:51.135 : Logged in
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.135 : ---> TYPE I
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.137 : 200 Type set to I.
DEBUG [virtcomui.VirtcomGUIOsnova] 4 Nov 2011 19:47:51.137 : Connected
DEBUG [virtcomui.VirtcomGUIOsnova] 4 Nov 2011 19:47:51.137 : deleting.
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.137 : ---> CWD user_podatki
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.139 : 250 CWD command successful.
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.140 : ---> CWD enalozbe
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.142 : 250 CWD command successful.
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.142 : ---> CWD prejete_fakture
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.144 : 250 CWD command successful.
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.145 : ---> CWD 01
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.147 : 250 CWD command successful.
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.148 : ---> DELE 2011_00000000_RACUN.jpg
DEBUG [FTPControlSocket] 4 Nov 2011 19:47:51.151 : 550 2011_00000000_RACUN.jpg : The system cannot find the path specified.
INFO [FTPControlSocket] 4 Nov 2011 19:47:51.152 : Expected reply codes = [200,250]

The program connects to server correctly and also changes directories to get to the folder named 01, where the file 2011_00000000_RACUN.jpg is located... I can upload files to the server with no problems (i uploaded this particular .jpg file as well) and I checked my permissions and I have full control over all these folders. The name of the file is ok, so I really don't have any idea what is wrong. I hope I got logging right and that u can help me with this...
0 votes
by (162k points)
Could you also post the log of when it succeeds? It would also be useful to call dirDetails() prior to the delete so we can see the directory listing.
0 votes
by (360 points)
here's the log when the file is deleted: (the name is a bit different, but 2011_00000001_RACUN and 2011_00000003_RACUN both exist in the same folder.

DEBUG [virtcomui.VirtcomGUIOsnova] 4 Nov 2011 21:26:16.047 : Connecting
DEBUG [FileTransferClient] 4 Nov 2011 21:26:16.048 : Configured client
DEBUG [FTPClient] 4 Nov 2011 21:26:16.048 : Connecting to /192.168.0.100:21
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.052 : 220 Microsoft FTP Service
DEBUG [FileTransferClient] 4 Nov 2011 21:26:16.052 : Client connected
DEBUG [FileTransferClient] 4 Nov 2011 21:26:16.052 : Logging in
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.052 : ---> USER viki
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.054 : 331 Password required for viki.
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.054 : ---> PASS ********
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.056 : 230 User viki logged in.
DEBUG [FileTransferClient] 4 Nov 2011 21:26:16.057 : Logged in
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.057 : ---> TYPE I
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.059 : 200 Type set to I.
Connected to FTP server.
DEBUG [virtcomui.VirtcomGUIOsnova] 4 Nov 2011 21:26:16.059 : Connected
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.059 : ---> CWD user_podatki
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.061 : 250 CWD command successful.
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.061 : ---> CWD enalozbe
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.064 : 250 CWD command successful.
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.064 : ---> CWD prejete_fakture
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.066 : 250 CWD command successful.
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.066 : ---> CWD 01
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.068 : 250 CWD command successful.
DEBUG [virtcomui.VirtcomGUIOsnova] 4 Nov 2011 21:26:16.068 : deleting.
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.068 : ---> DELE 2011_00000003_RACUN.jpg
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.071 : 250 DELE command successful.
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.072 : ---> QUIT
DEBUG [FTPControlSocket] 4 Nov 2011 21:26:16.074 : 221
DEBUG [virtcomui.VirtcomGUIOsnova] 4 Nov 2011 21:26:16.074 : deleted.

And here's what happens if i try to cal method directoryList("01"), where 01 is the folder with the .jpg files. That's how the call of the method looks like:
log.debug("dir. details:");
FTPFile[] directoryList = ftpDelete.directoryList(comCode);
log.debug("end of dir details");
log.debug("deleting.");
//sedaj smo v pravi mapi v kateri bomo pobrisali file z imenom imeScana
//ftpDelete.deleteFile(imeScana);
ftpDelete.deleteFile("2011_00000004_RACUN.jpg");
//na koncu se zapremo povezavo
ftpDelete.disconnect();
log.debug("deleted.");

and here's the log:
DEBUG [virtcomui.VirtcomGUIOsnova] 4 Nov 2011 21:29:49.600 : dir. details:
DEBUG [FTPControlSocket] 4 Nov 2011 21:29:49.600 : ---> SYST
DEBUG [FTPControlSocket] 4 Nov 2011 21:29:49.602 : 215 Windows_NT
DEBUG [FTPControlSocket] 4 Nov 2011 21:29:49.602 : ---> PWD
DEBUG [FTPControlSocket] 4 Nov 2011 21:29:49.605 : 257 "/user_podatki/enalozbe/prejete_fakture/01" is current directory.
DEBUG [FTPClient] 4 Nov 2011 21:29:49.605 : setupDirDetails(01) returning: /user_podatki/enalozbe/prejete_fakture/01/01
DEBUG [FTPControlSocket] 4 Nov 2011 21:29:49.605 : ListenOnAllInterfaces=true
DEBUG [FTPControlSocket] 4 Nov 2011 21:29:49.606 : ---> PORT 192,168,0,62,112,79
DEBUG [FTPControlSocket] 4 Nov 2011 21:29:49.608 : 200 PORT command successful.
DEBUG [FTPControlSocket] 4 Nov 2011 21:29:49.608 : ---> LIST 01
DEBUG [FTPControlSocket] 4 Nov 2011 21:29:49.610 : 150 Opening BINARY mode data connection for /bin/ls.
DEBUG [FTPActiveDataSocket] 4 Nov 2011 21:29:49.610 : Calling accept()
DEBUG [FTPActiveDataSocket] 4 Nov 2011 21:29:49.612 : accept() succeeded
DEBUG [FTPActiveDataSocket] 4 Nov 2011 21:29:49.612 : closeChild() succeeded
DEBUG [FTPActiveDataSocket] 4 Nov 2011 21:29:49.612 : close() succeeded
DEBUG [FTPControlSocket] 4 Nov 2011 21:29:49.816 : 550 01: The system cannot find the file specified.
INFO [FTPControlSocket] 4 Nov 2011 21:29:49.816 : Expected reply codes = [226,250]
com.enterprisedt.net.ftp.FTPException: 550 01: The system cannot find the file specified. //here the program stops and throws an exception
at com.enterprisedt.net.ftp.FTPControlSocket.validateReply(FTPControlSocket.java:1223)
at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3726)
at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3756)

It obviously has some problems with the directoryList, since it doesn't come to the "end of dir details" part...
0 votes
by (162k points)
Just call dirDetails("") - you can't supply 01 as the parameter if you are already in that directory.
0 votes
by (360 points)
I don't have the method dirDetails(), so i called directoryList("") and here's the log:
DEBUG [virtcomui.VirtcomGUIOsnova] 5 Nov 2011 10:29:48.166 : dir. details:
DEBUG [FTPControlSocket] 5 Nov 2011 10:29:48.166 : ---> SYST
DEBUG [FTPControlSocket] 5 Nov 2011 10:29:48.167 : 215 Windows_NT
DEBUG [FTPControlSocket] 5 Nov 2011 10:29:48.168 : ---> PWD
DEBUG [FTPControlSocket] 5 Nov 2011 10:29:48.171 : 257 "/user_podatki/enalozbe/prejete_fakture/01" is current directory.
DEBUG [FTPClient] 5 Nov 2011 10:29:48.171 : setupDirDetails() returning: /user_podatki/enalozbe/prejete_fakture/01
DEBUG [FTPControlSocket] 5 Nov 2011 10:29:48.171 : ListenOnAllInterfaces=true
DEBUG [FTPControlSocket] 5 Nov 2011 10:29:48.172 : ---> PORT 192,168,0,62,118,179
DEBUG [FTPControlSocket] 5 Nov 2011 10:29:48.174 : 200 PORT command successful.
DEBUG [FTPControlSocket] 5 Nov 2011 10:29:48.174 : ---> LIST
DEBUG [FTPControlSocket] 5 Nov 2011 10:29:48.176 : 150 Opening BINARY mode data connection for /bin/ls.
DEBUG [FTPActiveDataSocket] 5 Nov 2011 10:29:48.176 : Calling accept()
DEBUG [FTPActiveDataSocket] 5 Nov 2011 10:29:48.178 : accept() succeeded
DEBUG [FTPActiveDataSocket] 5 Nov 2011 10:29:48.178 : closeChild() succeeded
DEBUG [FTPActiveDataSocket] 5 Nov 2011 10:29:48.179 : close() succeeded
DEBUG [FTPControlSocket] 5 Nov 2011 10:29:48.377 : 226 Transfer complete.
DEBUG [FTPFileFactory] 5 Nov 2011 10:29:48.378 : Confirmed format Windows
DEBUG [virtcomui.VirtcomGUIOsnova] 5 Nov 2011 10:29:48.380 : end of dir details

If i print out the directory list that this method returns, it looks like this: - the list is ok.
F: 11-04-11 08:22PM 1040112 2011_00000002_RACUN.jpg
Name=2011_00000002_RACUN.jpg,Size=1040112,Permissions=null,Owner=null,Group=null,Is link=false,Link count=1.Is dir=false,Linked name=null,Last modified=04-11-2011 20:22
F: 11-04-11 08:59PM 539557 2011_00000005_RACUN.jpg
Name=2011_00000005_RACUN.jpg,Size=539557,Permissions=null,Owner=null,Group=null,Is link=false,Link count=1.Is dir=false,Linked name=null,Last modified=04-11-2011 20:59
F: 11-04-11 10:36PM 544147 2011_00000006_RACUN.jpg
Name=2011_00000006_RACUN.jpg,Size=544147,Permissions=null,Owner=null,Group=null,Is link=false,Link count=1.Is dir=false,Linked name=null,Last modified=04-11-2011 22:36
F: 11-04-11 10:46PM 539557 2011_00000099_RACUN.jpg
Name=2011_00000099_RACUN.jpg,Size=539557,Permissions=null,Owner=null,Group=null,Is link=false,Link count=1.Is dir=false,Linked name=null,Last modified=04-11-2011 22:46
F: 11-04-11 10:36PM 539557 2011_00000567_RACUN.jpg
Name=2011_00000567_RACUN.jpg,Size=539557,Permissions=null,Owner=null,Group=null,Is link=false,Link count=1.Is dir=false,Linked name=null,Last modified=04-11-2011 22:36
0 votes
by (162k points)
There has to be something simple going on here but I can't see what it is. Post the output of this (using the filename/dir that fails):

client.changeDirectory("dir1");
String fileName = "file1.jpg";
try {
client.deleteFile(fileName);
}
catch (FTPException ex) {}
client.deleteFile("file1.jpg");
client.disconnect();
0 votes
by (360 points)
Here's what the code looks like now:
ftpDelete.changeDirectory(comCode); //comCode is my directory
log.debug("deleting.");
String filename = preberiPropertiesFile("scanName");
try{
ftpDelete.deleteFile(filename);
}
catch(FTPException ex){}
ftpDelete.deleteFile(filename);
ftpDelete.disconnect();

And here's the log:

DEBUG [FTPControlSocket] 5 Nov 2011 17:27:00.830 : ---> CWD 01
DEBUG [FTPControlSocket] 5 Nov 2011 17:27:00.832 : 250 CWD command successful.
DEBUG [virtcomui.VirtcomGUIOsnova] 5 Nov 2011 17:27:00.832 : deleting.
DEBUG [FTPControlSocket] 5 Nov 2011 17:27:00.832 : ---> DELE 2011_00000005_RACUN.jpg
DEBUG [FTPControlSocket] 5 Nov 2011 17:27:00.835 : 550 2011_00000005_RACUN.jpg : The system cannot find the path specified.
INFO [FTPControlSocket] 5 Nov 2011 17:27:00.836 : Expected reply codes = [200,250]
DEBUG [FTPControlSocket] 5 Nov 2011 17:27:00.836 : ---> DELE 2011_00000005_RACUN.jpg
DEBUG [FTPControlSocket] 5 Nov 2011 17:27:00.840 : 550 2011_00000005_RACUN.jpg : The system cannot find the path specified.
INFO [FTPControlSocket] 5 Nov 2011 17:27:00.840 : Expected reply codes = [200,250]

I'm reading filename from a .properties file, if that could maybe cause problems?? But then I also read directoryName (comCode) from properties and it works fine...
0 votes
by (162k points)
Please put the filename explicitly the second time (the way you said it works). That way we will know what was sent to the server for the successful and failed deletes.
0 votes
by (360 points)
DEBUG [virtcomui.VirtcomGUIOsnova] 6 Nov 2011 00:35:37.815 : deleting.
DEBUG [FTPControlSocket] 6 Nov 2011 00:35:37.816 : ---> DELE 2011_00000005_RACUN.jpg
DEBUG [FTPControlSocket] 6 Nov 2011 00:35:37.819 : 550 2011_00000005_RACUN.jpg : The system cannot find the path specified. //if I call ftp.deleteFile(fileName);
INFO [FTPControlSocket] 6 Nov 2011 00:35:37.819 : Expected reply codes = [200,250]
DEBUG [FTPControlSocket] 6 Nov 2011 00:35:37.819 : ---> DELE 2011_00000005_RACUN.jpg //if I call ftp.deleteFile("2011_00000005_RACUN.jpg");
DEBUG [FTPControlSocket] 6 Nov 2011 00:35:37.823 : 250 DELE command successful.
DEBUG [FTPControlSocket] 6 Nov 2011 00:35:37.823 : ---> QUIT
DEBUG [FTPControlSocket] 6 Nov 2011 00:35:37.825 : 221
DEBUG [virtcomui.VirtcomGUIOsnova] 6 Nov 2011 00:35:37.825 : deleted.

Categories

...