»
S
I
D
E
B
A
R
«
JAVA: Using RNFR and RNTO with FTP
March 3rd, 2010 by admin

While trying to create a smart FTP client, I wanted to move a file from one location on the remote server to another. A brute-force method would be to delete the uploaded file, and then re-upload it to the proper directory. For the following reasons, this makes little to no sense.

  • You have wasted the original upload.
  • You will waste time deleting the original file.
  • You will waste time re-uploading the new file.
  • Rinse and repeat for x-number of files.

As a result of the above conclusion, I set off to find out which commands I could use to move the file instead of re-uploading it. Enter RNFR and RNTO. According to http://cr.yp.to/ftp.html, RNFR "asks the server to begin renaming a file." and RNTO "asks the server to finish renaming a file."

Armed with that knowledge, I was still having issues with the RNTO command. My response code kept returning 550 rename: No such file or directory. After many hours of anguish [research too, but it did not help], I finally discovered one key error in my code. I had accidentally added an extra space between my RNTO call and the new location.

RNTO  /usr/new/directory/filename.ext is not the same as RNTO /usr/new/directory/filename.ext

Alas, my many hours of beating my head on my desk came down to one erroneous space.

Nick


Leave a Reply

You must be logged in to post a comment.

»  Substance: WordPress   »  Style: Ahren Ahimsa